Sunday, March 27, 2011

Character Counter in Siebel

One of the admirable features of Siebel is its GUI, which allows us to accomodate all the frills and fancies of user. Recently i was asked by one of my colleague to implement i-want-this type of functionality which involved character counter for TextArea field, which should display count of remaining characters which could be filled, in standard siebel eService application. After hours of hit and trial, i came up with one dirty solution.

Lets consider we need to have character counter in place for Description(Maximum 250 characters) in form applet. A basic solution is to have a control below the Description which will display the count of characters left. The document Id for Description is 's_1_1_11_1' and Counter is 's_1_2_45_1'. We can obtain the document ids by richt click on the page. Now comes the key part where we need to add logic to count the characters in Description and populate the counter. This could be accomplished by HTML Attributes property of Description control with below code:

onKeyDown="function fn(){ document.getElementById('s_1_2_45_1').value = 250 - document.getElementById('s_1_1_11_1').value.length; }setTimeout(fn,100);"

The main thing here is on every keydown we are calling a function which will set/reset the counter. Get the length of Description and populating the counter with 250 - length. The issue with this approach is that counter can't be read only. If we make Counter field read only we will not be able to access it in function. Request all siebel champions here to use their fire fighting skills and suggest any other solution.

Happy Counting!!

Tuesday, March 22, 2011

Changing Primary

We can control whether user can change the primary in MVG which governs the visibility of business component. The primary in visibility MVG can only be modified in the admin views or views with Manager visibility. However there is a BC level user property which can disable this restriction.

Name: MVG Set Primary Restricted: visibility_link_name
Value: FALSE

Setting this user property to FALSE allows the Primary team member to be altered by someone other than the Manager or Siebel Administrator. In the earlier versions of siebel 6 this functioanlity was achieved by user property "MVG Set Primary Mode".

Let's say if it is required that any sales rep on the team can change the primary for opportunity then following user property will be required in Opportunity BC:

Name: MVG Set Primary Restricted: Position
Value: False

I have not tried this user property with other MVL's which are not related to visibility. So not sure whether it will behave in the same way or not.

Happy Crunching!!


Wednesday, March 9, 2011

Browser Scripting in Standard Interactivity

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

Tuesday, March 1, 2011

Ctrl-C:Ctrl-V::Drag:Drop

Reusability of components, objects, code, ...whatever, remains the most unfulfilled promise offered by any software methodology. However it is much more realistic when it comes to siebel. A mere push of Ctrl - B can create a clone of existing Object. But problem starts when any change comes which should be cascaded across all the cloned objects.
Recently i was bombarded with requirement of adding couple of columns to multiple applets. Querying each applet and creating new columns in each applet would have definitely killed me. But once again Professor Google and my colleague, Sandeep, came up with idea of "Compare Objects" which saved my life.

Consider a scenario were we have to add a single column to multiple list applets which are clone of each other. Let's take "Test SR Applet" as main applet and "Test SR Clone Applet" is clone applet. We need to add "Sub Status" column to both these applets. First add column to "Test SR Applet" manually.Map the column to web template. Now comes the interesting part of adding column to clone applet.

Query for both applets. Select both applets.


Rush to "Tools->Compare Objects->Selected".



Expand the "Test SR Applet" tree for "List -> List -> Column".



Hit on the right icon (tooltip says copy the object on the other side) to add the missing column from main applet to clone applet.

Same thing should be done on the "Applet Web Template Item" hierarchy. Once done save the changes, compile the object and look out for magic. It saved me lot of time and probably may help you during tough time.

Happy Cloning!!