Friday, August 2, 2013

Two Buttons with same Method Invoked = ShowPopup, displaying different popup applets!!

After reading the title of this post, you might have got some idea what the scenario I am going to talk about today. This is the scenario where I have two buttons exposed on the UI and both having the same Method Invoked = "ShowPopup".

Here below is the snapshot:

1.      Create SR        :           this button is being used for displaying “Create SR Popup Applet”.
2.   Create Order  :           this button is being used for displaying “Create Order Popup Applet”.

For configuring this simple requirement, you can have the following configuration:

“Create SR” Button
“Create Order” Button
Method Invoked = ShowPopup
Control User Properties
o   Popup = Create SR Popup Applet
o   Mode = Edit
Method Invoked = ShowPopup
Control User Properties
o   Popup = Create Order Popup Applet
o   Mode = Edit

No Issue till now. This pretty simple configuration would work fine!

But the problem comes in when there is a need to execute few lines of server script when each button is clicked, something like:
            If “Create SR” button clicked then
                        Set the Profile Attribute “NewEntityCreated” to “Service Request
                        Call the web service “X” to retrieve some values from other system.
                        After that display the popup applet : “Create SR Popup Applet”

            If “Create Order” button clicked then
                        Set the Profile Attribute “NewEntityCreated” to “Order Entry - Orders
                        Call the web service “Y” to retrieve some values from other system.
                        After that display the popup applet : “Create Order Popup Applet”

So, now the problem is, both button clicked will invoke the method “ShowPopup” and there is no way to identify which button is actually clicked.

Solution:
To overcome this, we have to have the different “Method Invoked” on each button.

1.      Instead of using “ShowPopup”, invoke the custom method for each button i.e.
a.      Method Invoke for “Create SR” button would be “CreateSR”.
b.      Method Invoke for “Create Order” button would be “CreateOrder”.

2.       Put the server script in PreInvokeMethod of the applet:
if(MethodName == "CreateSR")
            {
TheApplication().SetProfileAttr(“NewEntityCreated”, “Service Request”);
//         Code for calling the Web Service X
//         ……………………………………………………
//         ……………………………………………………
PopupApplet(“Create SR Popup Applet”);
                        return (CancelOperation);
            }
            if(MethodName == "CreateOrder")
            {

TheApplication().SetProfileAttr(“NewEntityCreated”, “Order Entry - Orders”);
//         Code for calling the Web Service Y
//         ……………………………………………………
//         ……………………………………………………
PopupApplet(“Create Order Popup Applet”);
                        return (CancelOperation);
            }
3.      Create a new Function as per below script:

function PopupApplet(strAppletName)
{
var oBSSLM = TheApplication().GetService("SLM Save List Service");
var psInp = TheApplication().NewPropertySet();
var psOut = TheApplication().NewPropertySet();
psInp.SetProperty("Applet Height", "400");
psInp.SetProperty("Applet Mode", "2");                          
psInp.SetProperty("Applet Name", strAppletName);
psInp.SetProperty("Applet Width", "800");
oBSSLM.InvokeMethod("LoadPopupApplet", psInp , psOut);
            }

Limitation of “SLM Save List Service” business service
If there is a requirement to display another popup applet from a button click on a Popup applet, then this business service doesn’t work and you might see the error:
View: <?> does not contain applet: <?>.(SBL-UIF-00401)

So, in this case the only choice is to either use “ShowPopup” method or if you can’t use it because of the scenario explained above (having two buttons with same Method Invoke i.e. ShowPopup) then other option is to use hijack the custom method invoked and invoke the Browser Script (for displaying popup applet) as explained here in earlier post.


How to display Popup applet in Siebel - Possible ways!!

Siebel provides various different OOB ways to display a Popup applet, no matter if it a list applet or form applet. Here below is the list of all possible ways:

1.     ShowPopup

This is a straight forward OOB way to display a popup applet which is mostly used to display a popup when button is clicked.

a.      Create a button control on the UI with Method Invoked = ShowPopup.
b.      Create following Control User Properties:

Name
Value
Comments
Popup
<Applet Name>
Name of the popup applet
Mode
<Mode>
Base, Edit, Edit List
Popup Dimension
<Height> X <Width>
Eg: 300 X 300

2.     From Server Script using business service : “SLM Save List Service”, Method: LoadPopupApplet

This method can be used as per below example:

var oBSSLM = TheApplication().GetService("SLM Save List Service");
var psInp = TheApplication().NewPropertySet();
var psOut = TheApplication().NewPropertySet();
psInp.SetProperty("Applet Height", "400");
psInp.SetProperty("Applet Mode", "1");                           // 1 - List Applet, 2 - Form Applet
psInp.SetProperty("Applet Name", "<Applet Name>");
psInp.SetProperty("Applet Width", "800");
oBSSLM.InvokeMethod("LoadPopupApplet", psInp , psOut);

3.     From Browser Script

Here below is the sample code to display applet via browser script:

      function Applet_InvokeMethod (name, inputPropSet)
{
if(name == "ButtonClick")
            {
                        inputPropSet.SetProperty("SWEMethod", "ShowPopup");
                        inputPropSet.SetProperty("SWETA", "<Applet Name>");
                        inputPropSet.SetProperty("SWEW", "300");
                        inputPropSet.SetProperty("SWEH", "100");
                        inputPropSet.SetProperty("SWESP", "true");
                        inputPropSet.SetProperty("SWEM", "<Mode>");  // Base, Edit, Edit List
                        this.InvokeMethod("ShowPopup", inputPropSet);
            }
            }

4.     From Command

This can be used if there is a need to display popup applet from toolbar button or some menu item:

Name
<Any name you want to give to Command>
Method
GotoApplet
Method Argument
ShowMode=<Mode>, Applet = <Applet Name>
HTML Popup Dimension
200 X 200                  (Height X Width)
ShowPopup
True
Target
Server


Friday, July 26, 2013

How to send Email in HTML Format with dynamic data and dynamic attachments?

After reading my earlier post on sending emails in HTML format, two readers Rishikesh and VP asked, if it is possible sending email using dynamic email template and with the attachments. After reading the complete requirement, I thought its worth a separate post. So, here is the solution - 


1. Lets assume we have an email template based on Quote business component as per below screen shot:



2. Create a Quote record as per below details:


3. Attach two files under the Quote in Attachments view:


So, now system is required to send the email in HTML format with dynamic data coming-up from the Quote record and that email should also have the attachments tied with the Quote.

Here below is the script to execute (you can create the workflow also as per your need)
====================================================================
// 1. Retrieve the email body after the substitution

var OCMBS = TheApplication().GetService("Outbound Communications Manager");
var psOCMInp = TheApplication().NewPropertySet();
var psOCMOut = TheApplication().NewPropertySet();
psOCMInp.SetProperty("CommTemplateName", "Template for Quote");   // Email Template Name
psOCMInp.SetProperty("SourceBusObj", "Quote");
psOCMInp.SetProperty("SourceId", "1-ALUGT");                                   // Row Id of the Quote Record
// Undocumented method for retrieving email body after substitution
OCMBS.InvokeMethod("ExpandCommTemplate", psOCMInp, psOCMOut); 
var strEmailBody = psOCMOut.GetProperty("ExpandedText");                // Get the Email Body
var strEmailSubject = psOCMOut.GetProperty("ExpandedSubject");        // Get the Email Subject

// 2. Retrieve the attachments path

var bsFINSService = TheApplication().GetService("FINS Industry BC Facility Service");
var psFINSInp = TheApplication().NewPropertySet();
var psFINSOut = TheApplication().NewPropertySet();
psFINSInp.SetProperty("BusObjName", "Quote");
psFINSInp.SetProperty("RootBusCompName", "Quote");
psFINSInp.SetProperty("FileBusCompName", "Quote Attachment");
psFINSInp.SetProperty("FileNameField", "QuoteFileName");                   
psFINSInp.SetProperty("RowId", "1-ALUGT");                                       // Row Id of the Quote Record

var QuoteBO = TheApplication().GetBusObject("Quote");
var QuoteBC = QuoteBO.GetBusComp("Quote");
var QuoteAttachBC = QuoteBO.GetBusComp("Quote Attachment");
with(QuoteBC)
{
ClearToQuery();
SetViewMode(AllView);
SetSearchSpec("Id", "1-ALUGT");                                               // Row Id of the Quote Record
ExecuteQuery();
with(QuoteAttachBC)
{
var isRecord = FirstRecord();
var strFinalFilePath = "";
while(isRecord)
{
psFINSInp.SetProperty("AttachmentId", GetFieldValue("Id"));
bsFINSService.InvokeMethod("GetFile", psFINSInp, psFINSOut);
strFinalFilePath = strFinalFilePath + "*" + psFINSOut.GetValue();
isRecord = NextRecord();
}
}
}

// 3. Send the email using “SendMessage”

psOCMInp.SetProperty("CommProfile", "SiebelMantra Profile");
psOCMInp.SetProperty("MsgHTMLBody", strEmailBody);
psOCMInp.SetProperty("MsgSubject", strEmailSubject);
psOCMInp.SetProperty("MsgToList", "siebelmantra@gmail.com");
psOCMInp.SetProperty("AttachFileList", strFinalFilePath);
OCMBS.InvokeMethod("SendMessage", psOCMInp, psOCMOut);

 ====================================================================

Finally, here below is the email that I received: