Vous êtes sur la page 1sur 3

How to Create a Business Service

This article explains how to create a Siebel business service. Many of us already know how to create a business service, however I have been asked a number of times to explain how to create one. A business service is basically a function or number of functions that can be called from many places in Siebel. A business service can be written to achieve functionality that could not be created without script. You can pass input values into and receive output values from a business service through a input and output process properties. A business service method is commonly executed from a workflow business service step, runtime event action, business service simulator, data validation method action, calculated field, EAI data maps, etc. We will now create a business service that will take a zipcode (postcode) as input and return value "Y" if the zipcode is a valid Australian zipcode. In Australia a valid zipcode must be numeric and 4 digits in length. In Siebel Tools lock the project that you want to create the business service in. Then in the Object Explorer (OE) click on Business Service > Business Service Method. In the Business Services list, right click and select New Record and enter the following detail in the new record: Name: Test Validate Postcode Display Name: Test Validate Postcode Project: [your project] Then in the Business Service Methods list create a new record and enter the following detail: Name: Validate Postcode Display Name: Validate Postcode Then in the OE expand the Business Service Method and click on Business Service Method Arg. In the Business Service Method Arguments list create the following new record: Name: Postcode Data Type: String Type: Input Storage Type: Property This is the input variable to the business service method. Now create another new business service method argument record as such: Name: Return Data Type: String Type: Input Storage Type: Property Now in Siebel Tools > Business Service list select the business service record Test Validate Postcode, then right click and select Edit Server Scripts from the right click menu. In the script window, select the Service_PreInvokeMethod script and enter the following code:
function Service_PreInvokeMethod (MethodName, Inputs, Outputs) {

var retval = ContinueOperation; try { switch (MethodName) { case "Validate Postcode": retval = CancelOperation; ValidatePostcode( Inputs, Outputs ); break; default: break; } } catch (e) { retval = CancelOperation; TheApplication().RaiseErrorText (e.toString()); } finally { } return (retval); }

This script will be executed when the business service method is executed, this will check the name of the method executed and execute the ValidatePostcode function if the method name is Validate Postcode. In the script window, click on the (declarations) script and enter the following ValidatePostcode function:
function ValidatePostcode(Inputs, Outputs) { var sPostcode = ""; var nLength; var sChar; var sCheck = /[ ]+/g; var bIsNum; var sRet = "Y"; var i=0; try { sPostcode = Inputs.GetProperty("Postcode"); nLength = sPostcode.length; if (nLength == 4) { while(i< nLength && sRet == "Y") { sChar = sPostcode.charAt(i); bIsNum = (Clib.isdigit(sChar)); if(bIsNum) { i++;

} else { sRet = "N"; } } } else { sRet = "N"; } } catch(e) { throw(e); } finally { Outputs.SetProperty("Return", sRet); } }

The above function will get the value of the Postcode input variable. It will check that the length is 4 and that it is numeric. It will return value "Y" if is a valid zipcode and will return "N" otherwise. Now save your scripts, close the script editor and compile the business service. We will now test the business service using the Business Service Simulator. Start Siebel dedicated client with the newly compiled srf. Navigate to Site Map > Administration - Business Service > Simulator. In the business service service list applet, create a new record with the following detail: Service Name: Test Validate Postcode Method Name: Validate Postcode Then in the Input Arguments list applet below, create a new record and click on the Property Name mvg glyph, in the Properties MVG enter a new record with the following detail: Name: Postcode Value: 2000 This is the input property to our business service. Save the MVG record and then click the Run button on the top applet. This will execute the business service. The Output argument values will be shown in the Output Arguments list applet below, note the value is "Y" because it is a valid zipcode. Change the value of the Input property Postcode value to an invalid zipcode and the output argument value will be "N".

Vous aimerez peut-être aussi