Bookshelf Home | Contents | Index | PDF |
Integration Platform Technologies: Siebel Enterprise Application Integration > Siebel Virtual Business Components > Custom Business Service Examples > Siebel eScript Business Service Example for a VBCThe following is an example of Siebel eScript implementation of a business service for a VBC. The fields configured for this simple VBC are AccountId, Name, Phone, Location, and AccessId. AccessId is the primary key in the external data source. AccessId is included in the VBC fields to make updating and deleting the fields simple and is configured as a hidden field. CAUTION: Do not use Siebel CRM system fields, such as Id, as output properties. Problematic application behavior might result. function Service_PreInvokeMethod (MethodName, Inputs, Outputs) { return(Init(Inputs, Outputs)); else if (MethodName == "Query") { return(Query(Inputs, Outputs)); else if (MethodName == "PreInsert") { return(PreInsert(Inputs, Outputs)); else if (MethodName == "Insert") { return(Insert(Inputs, Outputs)); else if (MethodName == "Update") { return(Update(Inputs, Outputs)); else if (MethodName == "Delete") { return(Delete(Inputs, Outputs)); function Init (Inputs, Outputs) { logPropSet(Inputs, "InitInputs.xml"); Outputs.SetProperty("AccountId", ""); Outputs.SetProperty("Name", ""); Outputs.SetProperty("Phone", ""); Outputs.SetProperty("AccessId", ""); Outputs.SetProperty("Location", ""); logPropSet(Outputs, "InitOutputs.xml"); function Query(Inputs, Outputs) { logPropSet(Inputs, "QueryInputs.xml"); var selectStmt = "select * from Contacts "; // You have the following properties if you want to use them // Inputs.GetProperty("Business Component Name") // Inputs.GetProperty("Business Component Id") // Inputs.GetProperty("Remote Source") // If you configured Maximum Cursor Size at the buscomp, var maxRows = Inputs.GetProperty("max-rows"); var searchString = Inputs.GetProperty("search-string"); // convert the search-string into a where clause searchString = stringReplace(searchString, '*', '%'); searchString = stringReplace(searchString, '[', ' '); searchString = stringReplace(searchString, ']', ' '); searchString = stringReplace(searchString, '~', ' '); searchString = stringReplace(searchString, '"', "'"); whereClause = whereClause + searchString; // match, search-spec, sort-spec var childCount = Inputs.GetChildCount(); for (var i = 0; i < childCount; i++) // Use this child property set if you want to use the old match field list. // We are not using this in this example. We'll use search-string instead. else if (child.GetType() == "search-spec") // Use this child property set if you want to use the hierarchical // representation of the search-string. // We are not using this in this example. We'll use search-string instead. else if (child.GetType() == "sort-spec") // This child property set has the sort spec. We'll use this in this example var sortFieldCount = child.GetChildCount(); for (var j = 0; j < sortFieldCount; j++) // Compose the order by clause. orderbyClause += sortProp.GetProperty("field"); var sortOrder = sortProp.GetValue(); if (sortOrder == "DESCENDING") // Now, our complete select statement is... selectStmt += whereClause + orderbyClause; // Now, query the data source. // We will return no more than maxRows of records. // Iterate through the record set and add them to the Outputs PropertySet. row = TheApplication().NewPropertySet(); var fieldValue = fields.Item(j).Value; row.SetProperty(fields.Item(j).Name, ""); row.SetProperty(fields.Item(j).Name, fieldValue); logPropSet(Outputs, "QueryOutputs.xml" ); function PreInsert (Inputs, Outputs) { logPropSet(Inputs, "PreInsertInputs.xml"); var defaults = TheApplication().NewPropertySet(); defaults.SetProperty("Location", "KO"); logPropSet(Outputs, "PreInsertOutputs.xml"); function Insert (Inputs, Outputs) { logPropSet(Inputs, "InsertInputs.xml"); // Inputs must have only 1 child property set. var child = Inputs.GetChild(0); var fieldName = child.GetFirstProperty(); fieldValue = child.GetProperty(fieldName); valueList += "'" + fieldValue + "'"; fieldName = child.GetNextProperty(); var insertStmt = "insert into Contacts (" + fieldList + ") values (" + valueList + ")"; // Now, inserting into the data source... // In this example, we must query back the record just inserted to get // the value of its primary key. We made this primary key part of the buscomp // to make update and delete easy. The primary key is "AccessId". var selectStmt = "select * from Contacts where "; fieldName = child.GetFirstProperty(); fieldValue = child.GetProperty(fieldName); whereClause += fieldName + " is null"; whereClause += fieldName + "='" + fieldValue + "'"; fieldName = child.GetNextProperty(); // Now, let's select the new record back // We're expecting only one row back in this example. var fcount, fields, row, fieldValue; row = TheApplication().NewPropertySet(); for (var j = 0; j < fcount; j++) fieldValue = fields.Item(j).Value(); row.SetProperty(fields.Item(j).Name(), ""); row.SetProperty(fields.Item(j).Name(), fieldValue); logPropSet(Outputs, "InsertOutputs.xml"); function Update (Inputs, Outputs) { logPropSet(Inputs, "UpdateInputs.xml"); var childCount = Inputs.GetChildCount(); var updateStmt = "update Contacts set "; // Go through each child in Inputs and construct the // necessary sql statements for update and query for (var i = 0; i < childCount; i++) fieldName = child.GetProperty("Field Name"); fieldValue = child.GetProperty("Field Value"); // We only have to update changed fields. if (child.GetProperty("Changed") == "true") setClause += fieldName + "=null"; setClause += fieldName + "='" + fieldValue + "'"; whereClause = " where AccessId = " + fieldValue; updateStmt += setClause + whereClause; // Now, updating the data source... // How to construct the Outputs PropertySet can vary, but in this example // We'll query back the updated record from the data source. var selectStmt = "select * from Contacts" + whereClause; // Now, let's select the updated record back // We expect only one row back in this example. // In this example, we're returning all the fields and not just // the updated fields. You can only return those updated // fields with the new value in the Outputs property set. var fcount, fields, row, fieldValue; row = TheApplication().NewPropertySet(); for (var j = 0; j < fcount; j++) fieldValue = fields.Item(j).Value(); row.SetProperty(fields.Item(j).Name(), ""); row.SetProperty(fields.Item(j).Name(), fieldValue); logPropSet(Outputs, "UpdateOutputs.xml"); function Delete (Inputs, Outputs) { logPropSet(Inputs, "DeleteInputs.xml"); // Inputs must have only 1 child property set. var child = Inputs.GetChild(0); // In this example, we're only using the AccessId // (it is the primary key in the Contacts db) // for the delete statement for simplicity. var deleteStmt = "delete from Contacts where AccessId = " + child.GetProperty("AccessId"); // Now, delete the record from the data source. logPropSet(Outputs, "DeleteOutputs.xml"); // Returning empty Outputs property set. The following functions are helper functions: // VBCContact is the ODBC data source name var connectionString = "DSN=VBCContact"; var conn = COMCreateObject("ADODB.Connection"); conn.Open(connectionString , uid, passwd); var rs = COMCreateObject("ADODB.Recordset"); function logPropSet(inputPS, fileName) { // Use EAI XML Write to File business service to write // inputPS property set to fileName file in c:\temp directory. var fileSvc = TheApplication().GetService("EAI XML Write to File"); var outPS = TheApplication().NewPropertySet(); var fileLoc = "c:\\temp\\" + fileName; tmpProp.SetProperty("FileName", fileLoc); fileSvc.InvokeMethod("WritePropSet", tmpProp, outPS); function stringReplace (string, from, to) { // Replaces from with to in string var stringLength = string.length; if ((stringLength == 0) || (fromLength == 0)) var fromIndex = string.indexOf(from); var newString = string.substring(0, fromIndex) + to; if ((fromIndex + fromLength) < stringLength) newString += stringReplace(string.substring(fromIndex+fromLength, stringLength), from, to); |
Integration Platform Technologies: Siebel Enterprise Application Integration | Copyright © 2013, Oracle and/or its affiliates. All rights reserved. Legal Notices. | |