Friday, October 29, 2010

Skype - Siebel Custom Integration

Want to call one of your contacts/prospects in Siebel without a lot of manual effort? now you can...
Here are a few simple steps of how you could integrate Skype with your siebel application.

Thank you Bernard for sharing this!

Configuration Steps - (for this example I am going to use the contacts applet)

Step 1: Create a custom Business service called 'OS Skype Integration' and assign it to a locked project.

place the below code in the PreCanInvokeMethod event of the Business Service

function Service_PreCanInvokeMethod (MethodName, &CanInvoke)
{
    if(MethodName == "GetField")
    {
        CanInvoke="TRUE";
        return(CancelOperation);
    }
    else if(MethodName == "TransformToSkype")
    {
        CanInvoke="TRUE";
        return(CancelOperation);
    }
    else
    {
        return(ContinueOperation);
    }
}


place the below code in the PreInvokeMethod event of the Business Service
function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
    try
    {
        switch (MethodName)
        {
            case "GetField":
                this.GetField(Inputs, Outputs);
                return (CancelOperation);
              
            case "TransformToSkype":
                this.TransformToSkype(Inputs, Outputs);
                return (CancelOperation);      
              
            default:
                return (ContinueOperation);
        }
    }
    catch(e)
    {
        TheApplication().RaiseErrorText(e.toString());
    }
    finally
    {
    }
}
Now that the two methods are defined and ready for use, lets define the logic inside them


Create two new functions as below -

GetField: This method as you can see will get the properties set by the Browser script in the Contact List Applet and will make them available in the Input Property Set of the Business Service.


function GetField(Inputs, Outputs)
{
    var sfield = Inputs.GetProperty("fieldname");
    var sId = Inputs.GetProperty("Id");
    var boName = Inputs.GetProperty("boName");
    var bcName = Inputs.GetProperty("bcName");
    var bo = TheApplication().GetBusObject(boName);
    var bc = bo.GetBusComp(bcName);
    bc.ClearToQuery();
    bc.SetViewMode(AllView);
    bc.ActivateField(sfield);
    bc.SetSearchSpec("Id", sId);
    bc.ExecuteQuery(ForwardOnly);
    if (bc.FirstRecord())
    {
        var svalue = bc.GetFieldValue(sfield);
           Outputs.SetProperty("fieldvalue",svalue);
    }
    else
    {
        Outputs.SetProperty("fieldvalue","");
    }
}


TransformToSkype: This method contains the main string used to make the call. The string includes the Skype exe path and teh Phone Number of the call recipient/Siebel Contact.


So, the string being passed would look something like this "C:\Progra~1\Skype\Phone\skype" /callto:+14152065351. This string is passed to the browser script for execution.

NOTE 1: The target customer base for the Client where I implemented this was for US only, thats why the '+1'. If you wish to make it more general you could check the Country of the contact and derive the country code based on that.

NOTE 2: You could also simply use 'callto:+14152065351' in the below script skiping an extra step(Step2 - Creating the LOV) - Thanks Ranjith for pointing that out.

function TransformToSkype(Inputs, Outputs)
{
    var sWorkphone = Inputs.GetProperty("PhoneNum");
    var sFirst = sWorkphone.charAt(0);
    var sSkypeNum="";
    var sLOVText = TheApplication().InvokeMethod("LookupValue","OS_SKYPE_PATH","Path");
    if(sFirst!="+")
    {
        sSkypeNum = "\"" + sLOVText + "\"" + " /callto:+1" + sWorkphone;
    }
    else
    {
        var sLast = "\n"
        var sSubstr = Clib.strstr(sWorkphone, sLast);
        var sRtn = sWorkphone.replace(sSubstr, "");
        //sSkypeNum = "skype:" + sRtn + "?Call";
        sSkypeNum = "\"" + sLOVText + "\"" + " /callto:" + sRtn;
    }
    Outputs.SetProperty("SkypeNum",sSkypeNum);
}


Step2: Create an LOV as seen in the below screenshot - This would contain the .exe path of Skype.









Step 3: Lock the 'Contact List Applet' and create three custom buttons as shown in the screenshot.(Note: The 'InvokeMethod property for the Skype buttons should be same as the ones in the script')
Make sure the buttons are clickable by using the CanInvokeMethod Applet User property.











You could also get more creative and use a 'Skype Toolbar' in Siebel. Like I have and call the business service from the Command Invoked. The Script would change in that case.(The Browser script from the applet would then be required on the Business Service)

 









Step 4:  Place the below script in the browser script evet Applet_PreInvokeMethod of the contact list applet.

code:
function Applet_PreInvokeMethod (name, inputPropSet)
{
    if(name=="Skype" || name=="SkypeCell" || name=="SkypeHome")
    {
        try
        {
            var serv = theApplication().GetService("OS Skype Integration");
            var inp = theApplication().NewPropertySet();
            var outs = theApplication().NewPropertySet();
            inp.SetProperty("Id", this.BusComp().GetFieldValue("Id"));
            switch(name)
            {
                case "Skype":
                    inp.SetProperty("fieldname","Work Phone #");
                    break;
                case "SkypeCell":
                    inp.SetProperty("fieldname","Cellular Phone #");
                    break;
                case "SkypeHome":
                    inp.SetProperty("fieldname","Home Phone #");
                    break;
            }
            inp.SetProperty("boName", this.BusObject().Name());
            inp.SetProperty("bcName", this.BusComp().Name());
            outs = serv.InvokeMethod("GetField",inp);  
            var svalue = outs.GetProperty("fieldvalue");
           
            inp = null;
            inp = theApplication().NewPropertySet();
            inp.SetProperty("PhoneNum",svalue);
            outs = null;
            outs = theApplication().NewPropertySet();
            outs = serv.InvokeMethod("TransformToSkype",inp);
            svalue="";
            svalue = outs.GetProperty("SkypeNum");
           
            //calls the ActiveXObject and passes the Skype exe path allong with the phone number of the contact

            var wsh = new ActiveXObject("WScript.Shell");
            var oExec = wsh.Exec(svalue);
            wsh=null;
            return ("CancelOperation");
        }
        catch(e)
        {
            alert ("Error Applet_PreInvokeMethod : " + e.toString());
        }
        finally
        {
            inp=null;
            outs=null;
            serv=null;
        }
    }
    return ("ContinueOperation");
}


This script will call the 'OS Skype Integration' and pass the respective Phone numbers for transformation if required.

Step 5: Since we are invoking the Business service from the browser level. The Business service will have to be registered as a client business sevice in the Application User Props
















Step 6: Compile all objects you modified.

Step 7: Compile the browser scripts by using Genb or should I say UltraGenB(A cool new utility created by Jason Le of Impossible Siebel)


Query on any contact in the Contact List Applet and hit one of the buttons....and there you have it...TRING TRING!!!

























Happy Calling!!



Share/Bookmark