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.

  1. 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;
}
}
  1. Add ‘COG Invoke Service in the client CFG
ClientBusinessService 51 = COG Invoke Service
  1. 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.

Comments powered by Disqus

Related Posts

4 Easy Ways to Export Data from Salesforce.com

Here are four easy ways for administrators and developers to export data from your salesforce.

Read More
2015 Top CRM Vendors Loose Market Share (2 exceptions)

2015 Top CRM Vendors Loose Market Share (2 exceptions)

I pride myself in keeping touch with the CRM technologies, I hit a road block in some aspects since no one tracks CRM market share on a day to day basis.

Read More
Custom CRM? You must be joking.

Custom CRM? You must be joking.

A not-so-recent question on Quora, custom crm vs non-custom crm , asked whether custom (=built from scratch) solutions for CRM are better than the standard products.

Read More