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!!



Wednesday, October 20, 2010

DVM - Length Restriction

Things can be real stinging when something works perfectly on your local and crashes on server. Recently i dated an error of database nature, which i always dread. "Error retrieving next record from the database (SBL-DBC-00104)" was constantly coming on server when we did query on our applet. It was working perfectly fine on my local machine. Server logs were not of much help as it constituted same error.
Things are not always what we see.After some hunting i discovered that issue was because of "Text Length Override" user property which was recently added. We wanted to restrict user with certain character limit in description field but there were existing records in that table where count of characters was greater than the limit which we gave in the user property for Description. So eventually the option of using this user property was ruled out as this Table was common across mulitple BusComps. Once again DVM came to the rescue. We created rule set with expression including Length function. Below expression was used for evaluation and DVM was triggered using Runtime events.

Length Check: IIf([Description] IS NOT NULL,Len([Description])<=1000,'Y')

The lifeline here is the Len function which returns the length of the given field.DVM support multiple functions which could be of immense use in real time scenarios. We will discuss more of DVM in future posts.

Data Validation Manager - Count

Siebel always give multiple ways to achieve desired solution. Recently we got a requirement which could be accomplished using different methods. We approached solution using "Data Validation Manager".

Problem Statement: User should not be able to Approve request if there is any activity associated in Open State.

Soln: A little configuration and DVM rule was good enough to run business.

a) Create a MVL in SR bc using with following Values

Name: Open Activity
Destination BC: Action
Destination Link: Service Request/Action
Type Field: Status
Type Value: Open

Compile BC.

b) Navigate to Application - Data Validation. Create a new rule set based on the BO Service Request. Go to Rules Tab. Create a new rule with following values.

Sequence: 1
Name: Open Check
Expression: Count("Open Activity") = 0
Business Component: Service Request
Apply To: Current Record
Return Code:

The key here is the name of the MVL."Count" function is directly used in the evaluation with MVL name. The best part is it doesn't require creation of calculate field in BC. Moreever DVM rules also require field used in expression to be exposed on applet or force active. They truly say everything positive comes with its own inbuilt negativity. But here the direct use of function in DVM comes as relief and also helps in keeping check at performance.

We will discuss more functions and expressions which could be used in the DVM rulesets till then happy commenting.

Thursday, October 14, 2010

UMF - Reloaded

Welcome back to the next (!last) post in UMF series. In this we will discuss how we can capture responses and perform actions from the popup applet. It basically involves two steps:

1 - Creation of business service with different methods which needs to be invoked on selecting responses from message applet.Create a new business service "ResponseService". Add three Methods to this BS:
AddInfo
AssignRequest
OpReq

function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
switch(MethodName)
{
case "AssignRequest":
fnAssignReassign(Inputs, Outputs);
return(CancelOperation);
case "AddInfo":
fnAddInfo(Inputs, Outputs);
return(CancelOperation);
case "OpReq":
fnOpReq(Inputs, Outputs);
return(CancelOperation);
}
return(ContinueOperation);
}
The best part is entire payload of the message is passed to the response thus allowing us to use them in response functions.

2 - Now its time to map the business service and methods to the responses. Navigate to Administration - Order Management -> Message Types. Query for "Testing UMF" message. Go to responses tab and map the corresponding Business service and Method to the respective response record.


Once all changes are done. Click on the Popup button and look out for the magic. UMF can be impressive alternate for browser script.

Wednesday, October 6, 2010

Unified Messaging Service Framework: Wealth of Messages

Many times we have resorted to browser scripts for displaying message and based on the input given have decided steps to follow but with the introduction of UMS the dependency on the browser script can be avoided. We can do wonders with the UMS framework which can really help in orchestration of system.

UMS is highly used in Order Management however Siebel is kind enough to allow us to use this for any other standard BO. However we need certain level of customization and scripting to achieve this. The main advantage of this framework is to invoke popup applets from workflow. I was not sure whether it was possible or not but as they say absence of evidence is not evidence of absence. A more than little help from support web and universal buddy Google made it. The details of Unified Messaging Service is available in OrderManagement guide. Here we will try to construct and invoke message from Service Request List Applet. It will display snapshot of Service Request which will help SR agent to work upon certain actions. Make sure you are working on SIA application. This goes in three steps:

1 - Creation of Message Type to be displayed.

a ) Navigate to Administration- Order Management -> Message Types.Create new record with following fields:

Name: Testing UMF
Display Mode: Active
Group:Internal Error Message
Title: Testing UMF
Short Text: Testing UMF
Full Text: Status: [Status]
Account: [Account]
Deparment: [Department]
Product: [Product]


b ) Navigate to Payload Tab. Define input payload fields as below:
Status
Account
Department
Product
These parameters will be replaced to actual values at runtime.


c ) Navigate to Response Tab this will hold the business service and method name to be invoked on clicking responses. Create following record in Response applet.

Sequence: 1
Name: Assign\ReAssign
Business Service: ResponseService // We will write this business service in later steps. Initially it can be left blank.
Method: AssignRequest

Sequence: 2
Name: Additional Information
Business Service: ResponseService
Method: AddInfo

Sequence: 3
Name: Opinion Request
Business Service: ResponseService
Method: OpReq

Now our Message set is done. Its time to invoke this message from applet. We will keep business service null for time being.

2 - Add the required BC's in the Service Request business object including "UMF Active Message Virtual BusComp", "UMF File Handler","UMF Passive Message Virtual BusComp".Navigate to Service Request List Applet. Add a button on the list applet with method as "Popup". Open script editor for this and add below script. This script will create message hierarchy at runtime to be invoked on button click.

if(MethodName == "Popup")
{
// Local declaration
var obj_UMS; // Business Service "Unified Messaging Service"
var obj_Inputs_PS; // Property Set used as inputs for UMS business service
var obj_Outputs_PS; // Property Set used as outputs for UMS business service
var obj_MessageList_PS; // Property Set used to construct the list of messages to be sent to UMS business service
var obj_Message_PS; // Property Set used to construct the message to be sent to UMS business service
var obj_Payload_PS; // Property Set used to construct the list of payload-value pairs be sent to UMS business service
var str_ErrMsg; // Used to create error message strings

// Variables initialization
obj_UMS = TheApplication().GetService("Unified Messaging Service");
obj_Inputs_PS = TheApplication().NewPropertySet();
obj_Outputs_PS = TheApplication().NewPropertySet();
obj_MessageList_PS = TheApplication().NewPropertySet();
obj_Message_PS = TheApplication().NewPropertySet();
obj_Payload_PS = TheApplication().NewPropertySet();
obj_Payload_PS.SetType("Payload");
//Creating Paload
obj_Payload_PS.SetProperty("Business Component","Service Request");
obj_Payload_PS.SetProperty("Status",this.BusComp().GetFieldValue("Status"));
obj_Payload_PS.SetProperty("Account",this.BusComp().GetFieldValue("Account"));
obj_Payload_PS.SetProperty("Department",this.BusComp().GetFieldValue("Department"));
obj_Payload_PS.SetProperty("Product",this.BusComp().GetFieldValue("Product"));
// Build message property set
obj_Message_PS.SetType("Message");
obj_Message_PS.SetProperty("Score", "100");
obj_Message_PS.SetProperty("Message Id", this.BusComp().GetFieldValue("Id"));
obj_Message_PS.SetProperty("Message Type", "Testing UMF");
obj_Message_PS.SetProperty("Display Mode", "Active");
obj_Message_PS.AddChild(obj_Payload_PS);

// Build message list property set
obj_MessageList_PS.SetType("Message List");
obj_MessageList_PS.AddChild(obj_Message_PS);
obj_Inputs_PS.SetProperty("Source", "SR Messages");
obj_Inputs_PS.AddChild(obj_MessageList_PS);

// Submit message to the unified messaging service
obj_UMS.InvokeMethod("AddMessages", obj_Inputs_PS, obj_Outputs_PS);
return (CancelOperation);
}

we can also write a business service and call that business service from workflow and invoke that workflow on button click. After compilation on button click following popup will appear.

The next important step is to capture responses and define appropriate actions. We will cover this in the next post till then stay tuned.