In this post we are going to discuss few best practices that we should follow while writing eScript. I don’t know who the author of this text is but would like say thanks to that guy for sharing these tips with us, I found it in an newsletter and thought of sharing it with all you guys.

Tip 1:

Avoid repeated calling of a function if the results returned are the same. Instead cache the value in a variable. Especially avoid repeated calling of the API function like TheApplication ().ActiveViewName() as shown below

Usual Practice :

if (TheApplication().ActiveViewName() == “View1” ||
    TheApplication ().ActiveViewName () == “View2” ||
    TheApplication ().ActiveViewName () == “View3”)

Best Practice:

var viewname = TheApplication().ActiveViewName();

if (viewname == “View1” || viewname == “View2” || viewname == “View3” )

Tip 2:

Delay Object Instantiation. If the object being used is under a conditional expression then wait till the conditional statement actually evaluates true. This reduces the cost and burden on the server. See the code below.
Usual Practice:

var BO = TheApplication().BusObject(“Contact”)
var BC = BO.GetBusComp(“Contact”)

if (status == “Pending”)
{
     BC.SetSearchSpec(“Id”,’12323’)
     BC.SetSearchSpec(“Status”,”Pending”)
}

Best Practice:

if (status == “Pending”)
{
     var BO = TheApplication().BusObject(“Contact”)
     var BC = BO.GetBusComp(“Contact”)

     BC.SetSearchSpec(“Id”,’12323’)
     BC.SetSearchSpec(“Status”,”Pending”)
}

Tip 3:

Use SetSearchSpec only on Indexed column. Before we do ExecuteQuery in the script, we use SetSearchSpec to retrieve only relevant records. SetSearchSpec also limits the number of records retrieved which makes the ExecuteQuery faster. But on what type of column we do SetSearchSpec on is also very important. We should always do a SetSearchSpec on indexed column so that the records are retrieved very fast. This saves a lot of burden and time on both application and database servers.

Tip 4:

When we use ExecuteQuery, we need not do execute query again on child BC. ExecuteQuery on parent BC also forces a query on all active child BC defined using Links. For example in the screenshot below, consider Account Object. There is Link defined between Account and Action BC. So if a query is executed on Account BC, only relevant Activity records pertaining to the records Account BC are retrieved. This behavior is very similar to searching in the Siebel application UI where if you have Account –Action view and if you query on Account applet, only activities relevant to are shown in the bottom list applet.

OkAvarageGoodVery GoodExcellent (7 votes, average: 3.29 out of 5)
Loading ... Loading ...