Wednesday, April 20, 2011

Prompt:Browser Script::LoadPopupApplet:Server Script

Whether we can repeat browser side capabilities via server side, like Alert/Prompt, always charms any developer. Server side "Alert" is beautifully explained on the siebel Impossible scriptless challenge using "LS SubjectVisits Service" business service with "ShowConfirmationDlg" method. Recently i was asked to implement Prompt sort of functionality using server side code. After some hits and lots of misses i came up with not so beautiful solution but it worked.

Lets consider a scenario where on click of "Summary" button, code should check the status of Service Request if it is "open" then it should prompt user to enter notes and capture these notes and put it in the Summay of service request.

The solution is blend of List of Value BC and pop up applet. I found a business service "SLM Save List Service"(thanks to Google again...wonder what life would have been w/o Google...) which could be used to invoke a popup applet from server side code. "LoadPopupApplet" mehtod is key here. It takes input as the name of applet to popup and the mode in which the applet should be displayed. I followed below steps to achieve desired requirement.

1 - Create a LOV of type "SR_POPUP". Keep the description blank and fill any random value in Name and Value. We will use the description field to be displayed in the Popup applet. Description will be used as temporary storage to user input.

2 - Create a pop up applet "SR Type Popup Applet" based on the "List Of Values" business component with search spec "([Type] = 'SR_POPUP' AND [Active] = 'Y')" . Only expose the Description field in this applet. Ensure that applet should have Edit web layout defined.

3 - Now comes the part where we write the script to popup the above applet and consume the input provided by user. The below code is written to invoke the applet and clear the description field once the processing is done.

For the "Summary" method in the "Service Request List Applet", below mentioned code is written.

if(MethodName == "Summary")
{
//Initial Processing to check the status of SR
if(this.Buscomp().GetFieldValue("Status") == "Open")
{
//Processing to clear the keyed in description by user
var sLOVBC = TheApplication().GetBusObject("List Of Values").GetBusComp("List Of Values");
with(sLOVBC)
{
ClearToQuery();
SetViewMode(3);
ActivateField("Description");
SetSearchSpec("Type","SR_POPUP");
ExecuteQuery();
if(FirstRecord())
{
SetFieldValue("Description","");
WriteRecord();
}

}
// code to popup the applet
var sBS = TheApplication().GetService("SLM Save List Service");
var sInput = TheApplication().NewPropertySet();
var sOutput = TheApplication().NewPropertySet();
sInput.SetProperty("Applet Name","SR Type Popup Applet");
sInput.SetProperty("Applet Mode","6");
sBS.InvokeMethod("LoadPopupApplet",sInput,sOutput);
}
return (CancelOperation);

}

For the "PickRecord" method in "SR Type Popup Applet" following code needs to be written for setting the "Abstract" field in SR.

if(MethodName == "PickRecord")
{
TheApplication().ActiveBusObject().GetBusComp("Service Request").SetFieldValue("Abstract",this.BusComp().GetFieldValue("Description"));
this.BusComp().SetFieldValue("Description","");
this.InvokeMethod("CloseApplet");
return (CancelOperation);
}

This is approach by which one can popup an applet and allow user to enter something and then do further executions. Please do share alternates to prompt in server script.

Happy Prompting!!



6 comments:

Anonymous said...

Excellent!!

Siebelish said...

Thanks Anonymous...

JMacZ said...

Awesome find!

Keep in mind that Applet Mode of 6 assumes an Edit List. For Edit, use Applet Mode 3.

Siebelish said...

Thanks JMacZ for the insight.

Regards,
-Rahul-

Unknown said...

I tried using the above code. It does not work. Please help..
My popup applet is of 'Standard' type and has a class 'CSSSWEFrameListPopup'.

Thanks in advance for any help.

Royden

Siebelish said...

Hi,
You need to keep 6 or 3 for applet type.

Regards,
-Rahul-