Server and Browser Script Examples

Define the following server script in the CTI_Test business service. The PreCanInvokeMethod server script in the CTI_Test business service allows the SWE command to be enabled that in turn invokes the browser-layer scripting business service method Alert:

function Service_PreCanInvokeMethod (MethodName, &CanInvoke)
{
   var ReturnVal = ContinueOperation;
   if (MethodName == "Alert")
   {
      CanInvoke = "True";
      ReturnVal = CancelOperation;
   }
   return ReturnVal;
}

Define the following browser scripts in the CTI_Test business service. The PreInvokeMethod browser script invokes the Alert method to create an alert box in the browser.

function Service_PreCanInvokeMethod (methodName)
{
   if (methodName == "Alert")
      return true;
   else
      return ("ContinueOperation");
}
function Service_PreInvokeMethod (methodName, inputPropSet, outputPropSet)
{
   if (methodName == "Alert")
   {
      alert("CTI browser script test");
      return ("CancelOperation");
   }
   else
      return ("ContinueOperation");
}

In the previous steps, you have successfully created a new communications command named Alert. You can execute this command, for example, from the Communications submenu of the Tools menu, or from a keyboard shortcut. Another option is to further integrate this command with a server script, as illustrated in the following server script example:

function BrowserScriptTest()
{
   // Invoking Browser Script
   var ctibs = TheApplication().GetService("Communications Client"); 
   var ip = TheApplication().NewPropertySet();
   var op = TheApplication().NewPropertySet();
   ctibs.InvokeMethod("Alert", ip, op);
}