Call Server Script from Browser Script without CFG Changes
If you are one of the unfortunate souls stuck deploying Siebel local clients - you know how annoying is to setup package and deploy it to the users from time to time. I have never seen an implementation where this goes smoothly for months - there is always some wrinkle to iron out.
The reason I bring this up is relevant to the topic. Every CFG file has to be deployed to the client using the package manager. And, this includes changes to the CFG to add/change parameter that enables browser script to call server script business services.
For every business service that needs to be called from browser, you use the following line -
ClientBusinessService n = <Business Service Name>
// n is a number in increments
Each new service that has to be called from browser script will need this change. Each of those changes will need deployment to the local clients.
Agreed that you don’t add server business services that need to be called from browser every other day. But, why go through this pain when there is a simple work-around available?
This “method” is nothing new - just go and create a generic business service that can call other business services on demand. Take the service name as input parameter in the generic business service.
- Create business service ‘COG Invoke Service’
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
var iReturn = ContinueOperation;
try {
switch(MethodName){
Case "InvokeService":
var sService = Inputs.GetProperty("Service");
var sMethod = Inputs.GetProperty("Method");
if (sService == "" || sMethod == "")
TheApplication.RaiseErrorText("Service name or Method name is blank. Provide 'Service' and 'Method' parameters in the calling service.");
var bsInvoke = TheApplication().GetService(sService);
bsInvoke.InvokeMethod(sMethod, Inputs, Outputs);
iReturn = CancelOperation;
break;
} //switch
} //try
return (iReturn);
catch(e) {
throw(e);
}
finally {
bsInvoke = null;
}
}
- Add ‘COG Invoke Service in the client CFG
ClientBusinessService 51 = COG Invoke Service
- Invoke the new service from all browser scripts and just change the parameter value.
try {
var psIn = theApplication().NewPropertySet();
var psOut = theApplication().NewPropertySet();
psIn.SetProperty("Service","COG Super Service");
psIn.SetProperty("Method","DoAmazingThings");
psIn.SetProperty("Account Id", "1-ABC"); //pass to the destination service
var bsService = theApplication().GetService("COG Invoke Service");
bsService.InvokeMethod("Invoke Service", psIn, psOut);
}
finally {
psOut = null;
psIn = null;
bsService = null;
}
This can be easily extended to pass entire property sets as parameters instead of simple strings. Just change the service to pass any child property sets to the caller in addition to the properties in the root.