Example Business Service

This example provides sample code for a business service that you can use to retrieve and decode data; note however that the search specification is arbitrary. Carefully consider this search specification for individual implementations. You can apply a search specification to only fields that map to physical columns, and not to encoded fields.

/***********************************************************************************/
/* function: decodeAuditTrail
/*
/* The top level function to read audit trail data encoded in Siebel 8.x format    */
/* allowing the data to be exported as simple value pairs for purposes of archival */
/* or business intelligence.                                                       */
/************************************************************************************/
function decodeAuditTrail(strTimediff)
{
try {
	// Create objects
	var boAudit = TheApplication().GetBusObject("Audit Trail");
	var bcAuditItem = boAudit.GetBusComp("Audit Trail Item 2");
	with(bcAuditItem) {
	   SetViewMode(AllView);
	   ClearToQuery();
	   // Set the search specification. In this example we are only
	   // using time differential.
	   SetSearchSpec("Date", ">= " + strTimediff);
	   ExecuteQuery(ForwardOnly);
	   var bRecord = FirstRecord();
	   while(bRecord) {
			//Retrieve field values
			var strRecordId = GetFieldValue("Record Id");
			var strBC = GetFieldValue("Business Component");
			var strFieldName = GetFieldValue("Field");
			var strOldVal = GetFieldValue("Old Value");
			var strNewVal = GetFieldValue("New Value");
			var strDate = GetFieldValue("Date");
			//Query for underlying Row Id
			/**************************************************************************/
			/* function: getAuditRowId                                                   */
			/*
			/* Retrieves the physical row ID associated with the decoded audit record to */
			/* provide a defined cutoff for the audit export operation. In cases where   */
			/* more than one record is retrieved, an error is thrown because the defined */
			/* cutoff is not unique, and the operation is retried with new parameters.   */
			/**************************************************************************/
			var strAuditId = getAuditRowId(strRecordId, strDate);
			//Placeholder for function to write out values
			writeAuditValues(strAuditId, strBC, strFieldName, strRecordId,
			strOldVal, strNewVal, strDate);
			bRecord = NextRecord();
		}
	}
}
catch(e)
{
	throw(e);
}
}
function getAuditRowId(strAuditRecordId, strAuditRecordDate)
{
	var strReturn = "";
try
{
	// Create objects
	var boAudit = TheApplication().GetBusObject("Audit Trail");
	var bcAuditData = boAudit.GetBusComp("Audit Trail Item - Data");
	with(bcAuditData) {
		SetViewMode(AllView);
		ClearToQuery();
		// Set the search specification for the combination of
		// record Id and date
		SetSearchSpec("Date", strAuditRecordDate);
		SetSearchSpec("Record Id", strAuditRecordId);
		ExecuteQuery(ForwardOnly);
		var bRecord = FirstRecord();
		if(bRecord) {
			strReturn = GetFieldValue("Id");
			// Check to see that we only have one record
			bRecord = NextRecord();
			if(bRecord) {
			throw("Error: Multiple Record Id and Date records
			identified");
		}
}
else
	strReturn = "";
}
}
catch(e)
{
	throw(e);
}
	return(strReturn);
}