I have never been fan of SI applications because of the unpredicatble limitations it offers. But however recently one of my friend cum life saver,Vinay Jain aka Vivacious,asked me a trivia and i was forced to jump into the ocean. Browser scripting incapabilities in SI mode is wastly documented but it is not mentioned how a well written server side code can compensate for the browser scripting.The reason that the browser script code doesn't run in standard interactivity client is because of unavailability of Siebel objects and methods.However Siebel is generous enough to provide some DOM events which could be effectively used to carry out desired task.Sometimes it is necessary to fetch field values in the browser code or to click button that navigate user to different link. Lets try to explore these scenarios in this post.
Problem Statement: Need to open a url on click of button on SR detail applet which requires SR number to be appended as argument.
Solution: The very first challenge here is to get the value of SR#. As the buscomp methods are not supported we have to go to traditional java script to fetch the value of SR#. For this we need to find the HTML attribute id of the control SR# displayed on the applet. This could be accomplished in two ways:
1 - Populate the HTML Attribute property in the Control to "id=SRNumber" in the form applet for the Control SR#.
2 - Right click the applet and View Source. Determine the SR# control and check out for Siebel generated html attribute. This will somewhat look like "span id='s_5_1_23_0'".
Now next step is to open the Browser Script for the "CUT Service Request Detail Applet (eService)" and navigate to the On click event of the button "VJ". Add following piece of code. Compile and confirm.
function Edit__0__Control__VJ__onclick (applet, id)
{
//Either of sTest or sSR could be used.
//var sTest = document.getElementById("s_5_1_23_0").value;
var sSR = document.getElementById("SRNumber").value;
window.open("http://www.customersystem.com/index.php?id="+sSR);
// This will pop up the url with SR # appended
}
So far so good. But the words "Luck" and "Siebel eService" have not always sat comfortably together for me. Trouble starts when the field under equation is not displayed on the applet or is read only. In either of scenarios it is not possible to fetch the value by using getElementById function. Another fascinating approach as suggested by support web is to generate HTML on the server side only for the control. In this approach we can get value from any field or any profile attribute.
1 - Write a dummy code on the On click event
function Edit__0__Control__VJ__onclick (applet, id)
{
//Either of sTest or sSR could be used.
}
2 - Open the server side script and go to "WebApplet_ShowControl" event. The main idea here is to re-generate the HTML for the button.
function WebApplet_ShowControl (ControlName, Property, Mode, &HTML)
{
if ((ControlName == "VJ") && (Property == "FormattedHtml"))
{
var a = HTML.indexOf("onclick");
var b = HTML.indexOf("'",a+1);
var c = HTML.indexOf("'",b+1);
if ((a > -1) && (b > -1) && (c > -1))
{
var sr = this.BusComp().GetFieldValue("SR Number");
//Defining function on click
var t = "onclick='window.open(\"http://www.customersystem.com/index.php?id=" + sr +"\")'";
var HTML2 = HTML.substr(0,a) + t + HTML.substr(c+1);
HTML = HTML2; // Re-Generating HTML
}
}
}
This function will overwrite the HTML generated by the SWE engine in SI and will include the code defined in the Showcontrol event. The best part here is we can execute application and buscomp methods to get the value which is required to pass in the url. With blend of Java and HTML one can really do wonders with the application.
Happy Scripting!!