Showing posts with label eScript. Show all posts
Showing posts with label eScript. Show all posts

Wednesday, May 7, 2008

Siebel How To - enable or disable a button conditionally?

I was working on my desk one day and newbie to siebel approached me to ask a question(also a avid reader on asked me the same question on mail). He asked me about a simple requirement or rather I should say the requirement that appeared simple to me.

The requirement was :

A button on an Applet should be enabled if a particular user logs into the application otherwise it should remain disabled.The Solution is a simple script that we can write on Applet_PreCanInvoke event to enable or disable a button conditionally.

I am providing the pseudo code for that script below

function WebApplet_PreCanInvokeMethod (MethodName, &CanInvoke)
{
if (MethodName == "UrButtonMethod")
{
if(UserLogin == "AuthorisedUser")
{
CanInvoke="TRUE";
return (CancelOperation);
}
else
{
CanInvoke="FALSE";
return (CancelOperation);
}
}
}

There is just one catch in the above mentioned code. How will you find that user is the authorised user or not. There are several ways of doing it some are easy and some are difficult.

I will tell you the easiest way to do that. You just need to write one line of code to accomplish that which is as following.

if(TheApplication().GetProfileAttr("Me.Login") == "AuthorisedUserLogin")

There is a whole bunch of such kind of profile attributes that are available to us all the time in the whole application, we can use them anywhere we want. But discussion on Profile Attributes is subject of another post. So, come back for more.

If this post was helpful to you, Please post your comments or suggestions to make this site better.

NextRecord DeleteRecord - Use with caution!!

Number of times we have written code in which we have to traverse number of records in a loop and n number of times we have missed one important statement that results in our code to stuck in infinite loop. Yes, I am talking about the statement Object.NextRecord()

This statment is generally used at the end of the loop so that after all the processing is complete we move on to the next record in the record set and perform processing on the next record. I am giving a Psuedo code to explain that.

while(not end of recordset)

{

perform operation

recordset.NextRecord()

}


But here I am going to to tell you about a situation where doing a NextRecord(). will result in problems. Yes, I we are deleting the records in the loop then we don't need to use the NextRecord() function.


Reason for that is using DeleteRecord() results in pointer to moved to next record automatically and if we use NextRecord then it will result in skipping of the last record we are trying to delete. Pseudo to explain this

while(not end of RecordSet)

{

do processing

recordset.DeleteRecord();

// recordset.NextRecord(); // no need to use next record as delete will automatically move the pointer to next line

}

Hope this tip is helpful. Happy Scripting :)

Siebel CRM How To – Restrict a Field to only Accept Certain Characters?

Requirement:

  • We have a multilingual application and we have Unicode enabled database but still we would like to restrict user from entering certain characters.

  • We want to prevent user from entering numbers in alpha-numeric fields.
Solution:

Use charCodeAt function given by Siebel but not documented properly by Siebel. Here I am giving a Pseudo code to explain how it can be used.

if (FieldName == "First Name") {
for (var i=0;i less than field length ;i++) {
var ASCII_code = fieldvalue.charCodeAt(i)
if(ASCII_code is not valid code)
Error("Not Valid Code");
}}


charCodeAt() returns the ASCII code of the character that is supplied to it. ASCII code comparison is way faster than the number function that are used to compare strings so we can also use this function where we want to compare two strings by just modifying the above given Pseudo code.

Hope this helps! If yes, Please put your comments below.

Siebel eScript – How to track performance with Timing Scripts

Timing scripts can come in handy to know exactly how much our code is taking to execute. There can be several reasons for doing this.

  • We are calling several business services in code and we need to know performance of each one.
  • We need to know time our script on business component, Applet is taking
  • We have several approaches to solve the problem and need to know the exact time taken by each.
The code to achieve that is:

var fileVar = Clib.fopen("c:\\Timing.txt", "at");
var timeVar = Clib.ctime(Clib.time());
Clib.fputs(timeVar + ": Starting trace in of code", fileVar);

//code which you want to track time
…………………………………….
…………………………………….

timeVar = Clib.ctime(Clib.time());
Clib.fputs("Ending trace of code: " + timeVar, fileVar);
Clib.fclose(fileVar);

PS: This code will work only if you are trying to run it in dedicated client or your Siebel server is windows server. This code will fail if you are trying to run it from thin client and your Siebel Server is a unix server as it will not able to find the path. You will have to change the path to unix path e.g. /apps/srvr/bin if your server is unix.

Hope this helps!!!!

Siebel eScript – An Overview

Scripting is one of the most important areas in Siebel Development but irony is that it is never recommended to write script in Siebel. Siebel scripting is done in a language known as eScript. eScript shares it’s syntax with JavaScript. If you have worked in JavaScript then you would find it pretty easy to adapt to eScript.

eScript can be broadly classified into two categories

  • Server Scripts
  • Browser Scripts
Server Scripts: as its name suggests is executed on server side. Which means that the user request is sent to server where the scripts is then executed

Browser Script: is actually converted into JavaScript and is executed on client side.

Usually scripting is written on objects in Siebel such as Applets, Business Components etc. But the main use of eScript is done to write Business Services. There are lots of things that you achieve through a business service. Detail discussion on business service is subject to different post but it is similar to somewhat workflows implementing complete business processes with the help of script.

Scripting should be used as a last resort. Everything can be done through script of course but it makes the manageability and up gradation of Application difficult.

But as I said in my earlier post to be a successful Siebel developer Scripting and Configuration should be your strong points. Scripting can be fun but should be avoided as long as possible

Siebel Profile Attributes - an Overview.

Profile Attributes I stumbled upon them in siebel when I was working on my first assignment involving Siebel EAI. Till that time I had only used and heard of Global Variables which you could use throught out your script.

But as the requirement said only if user clicked a button in View A and then performed some particular action in View B trigger a workflow.

As views involved had different BC's it was not possible to have done through global variables. Then my senior colluege introduced me to a new entity in siebel called 'Profile Attributes'. They are important because they have a unique property. They are available throughout the application. The best term that comes to my mind to describe them is 'Session Variables'. Those who have worked a little bit on development of Web Application will understand exactly what I am saying and for those who hasn't worked on them I will explain.

As you know from siebel 7 onwards it has Web Architecture. So, as soon as you login into siebel through your browser a session is started which last till time you log out or you close your browser window or according to the length set through session parameter at server level.

Now discussing in details that how server maintains this session and what goes on behind the scene is out of scope of this article
but what you need to know is that Siebel server recognises every unique user through session id that is given to you when you login to siebel and it remains valid until you session closes due to above mentioned reasons. So, Profile Attributes are variables that can hold any value during the session of the user. There are two methods available to in siebel escript that help you to work with Profile Attributes.

  • GetProfileAttr
  • SetProfileAttr

GetProfileAttr method is used to retrieve the value of a particular profile attribute. The syntax is

TheApplication().GetProfileAttr("ProfileAttrName")

SetProfileAttr method is used to set the value of Profile Attribute. If the Profile Attribute that you mention is not already existing it creates a new Profile Attribute. The syntax is

TheApplication().SetProfileAttr("ProfileAttrName",Value)

So, to accomplish the our requirement we Set a profile attribute when clicked the button on view A and then when he went to View B and did the particular action we wanted we retrieved the value of the profile attribute and if all the conditions were met we executed the workflow and everybody developed happily ever after :)

But, there is a twist in the story and it was not a happy ending after all which highlights the fragile nature of Profile Attributes. Now, in a particular situation this solution won't work. If user clicked button on View A and then logged off which meant profile attribute is destroyed hence the functionality failed. So, as you all must have guessed this solution was scrapped :(

So, the moral of the story is use Profile Attributes with caution and only if you are sure that if the session is destroyed you functionality wouldn't fail.

All Rights Reserved