A lot of readers have requested me to include real life scenarios with solutions. Hence I have been hunting for requirements on web which I can discuss with you guys. During my surfing yesterday I came across a requirement which I would like to share with you.
I am sharing it with you not because it has an interesting or complex solution but, to emphasize the fact that there are always several ways to achieve a things in Siebel and completing the requirement should not be your only goal as doing it in a wrong way can severely hamper the long term life of your application. You should always ask this question to yourself.
Is there a better way to do it?
Well now not wasting much of your precious time let’s get on with the requirement.
Requirement:
- On Service Agreement list applet we have a button ‘move to batch’
- User can select all contracts, or 1 or more contracts using CTRL button, and move these to his batch for executing renewals.
- User should not be able to add same contract twice in renewal batch for this ‘User key’ has been used and if user tries to do this he will get “Record with same values already exists” error
Here is the part of requirement that forced me to write this post.
- In eScript code I want to ignore or suppress this particular error and if this comes it should execute the code for next error.
My Thoughts:
This is absolute wrong way to do this requirement even if you can do it. What you should be doing is to do write your script in such a way that this error doesn’t come at all and there are several easy ways to ensure this.
Here is the approach I would have used to accomplish the requirement
Solution:
In the Applet server Script write the code to implement following logic (I am not providing the complete code).
var isRecord = BC.FirstSelected();
while(isRecord)
{
Call a workflow and pass the field values that are part of user key
isRecord = BC.NextSelected();
}
In the Workflow I would query for the record with the values that are passed.
If record is found then go to End step otherwise call the Business Service to create a new record or may be use Insert step and avoid all scripting all together.
The decision to use Insert Step or BS will depend on how complex the logic is to create the record.
If it is simple insertion then pass the values of the required field in the workflow and use it in insert step but if certain kind of data manipulation or validations are required then you can use a BS to do your job.
If you think there is another better way to do it then do let me know. Your comments are always welcome.


4 Comments at "Handling errors in eScript – Case Study"
Hi Neel,
the requirement for “parsing the user selection” comes quite often, so this might be a good opportunity to write a business service which implements the necessary logic. Then you could use that business service in a workflow and call the workflow from the applet button (using “Named Method” user property e.g.). Doing so you avoid scripting at the applet level, which is the #1 pain point in so many projects especially during upgrades. You never know how the UI will work in a future release, but you know how the business layer will work. Two more arguments for this approach is that it is a) completely compatible to Siebel standard and b) if written in a generic manner, you can reuse your business service with other entities. A backdrop is of course the amount of time you need to implement such a super-generic service.
Have a nice day
@lex
Neel-
This is really a cool approach. In one of my recent project, the mission was to convert most of the scripts into declarative solutions. I have applied similar approach and achieved the goals.
My thoughts here:
I guess this is a real time action against batch transaction and hence I assume that it is considered for workflow. Also, I am not sure about the way error handling is needed and done in this case. However it is also important that error handler plays an added role, in determining solution selection.
Another option on same requirement is given below, which may or may not be absolute though.
-Using Named method to call workflow
var isRecord = BC.FirstSelected();
while(isRecord)
{
Return(Named method Name);
For ex: return(”ABCBookOrder”); this goes to call a workflow and pass the field values that are part of user key)
isRecord = BC.NextSelected();
}
All the Best
Harish.K
You don’t need the While … juste write you code for one record and use “Named Method n” user property with “INVOKESEL” action
At my work, I have seen a more elegant approach to the similar problem above
In PreCanInvokeMethod, I found this
function WebApplet_PreCanInvokeMethod (MethodName, &CanInvoke)
{
return TheApp.Get(”Applet”).ButtonEnable(this.Name(), MethodName, CanInvoke, this.BusComp());
}
Here are the interesting points:
- The line above is actually the ONLY single script you ever needed for the Applet. If you add more buttons or actions, you don’t need to modify this Applet anymore. The Named Method is much less flexible to this solution as it can’t pass the critical traceable information.
- The action implementation is shifted to a BS which is also quite different from the normal BS. You would probably see something like this
case this.ButtonName_XXX:
TheAgreement.Renew(TheTheSys.GetSelectedRecId(oBC),true);
break;
TheAgreement.Renew() is the only Agreement’s renewal function across application as long as you passed in the Agreement’s row Id. The “true” argument is basically telling you whether you wanna suppress the popup window for alerting user. If this function is invoked on Applet, you might want to alert user if necessary such as “Record with same values already exists for Agreement #12, #34…”. If this function is invoked from batch workflow, you might wanna suppress this.
TheAgreement.Renew() has the delicate logic to take care of the renewal process from the global aspect.
TheSys.GetSelectedRecId(oBC) is a generic function that returns the row id of user-selected records. When I looked at its implementation, bravo!!! I was surprised of its genius coding other than using the while loop.
I didn’t write any of this code above. I took over the works from previous consulting firm Amazxxx Gloxxx. However I can tell this framework made my life easier, and it is far beyond anything I can discuss it more here.
Comment Now!