You are on page 1of 4

Sample Scripts

Scenario # 1

Business Component: Opportunity


Where: Server Script
Scenario: When a user closes a Opportunity, update the Closed By field
with the user's login id

IN TOOLS

Lock the Opty Project.

On the Business Component Opportunity, RCNR and fill in the following details.

Name: Closed By
Join: S_OPTY_X
Column: ATTRIB_47

On the Opportunity Business Component, right click and choose Edit Server Script. Choose
eScript as your language of scripting. On the PreSetFieldValue event, write the code below.

function BusComp_PreSetFieldValue (FieldName, FieldValue)


{
if (FieldName == "Sales Stage") {
if(FieldValue == "09 - Closed/Won"){
this.ActivateField("Closed By");
this.SetFieldValue("Closed By",TheApplication().LoginName());
}
else{
this.ActivateField("Closed By");
this.SetFieldValue("Closed By","");
}
}
return (ContinueOperation);
}

Hit the Save button. Compile the Opportunity Business Component by right-clicking on the
Opportunity Business Component and choosing Compile Selected Object.

Open Client and test the code.


Scenario # 2

Business Component: Account


Where: Server Script
Scenario: When SADMIN creates a new Account, default the Account Type
as “Commercial”

Lock the Account Project.

On the Account Business Component, right click and choose Edit Server Script. Choose eScript
as your language of scripting. On the NewRecord event, write the code below.

function BusComp_NewRecord ()
{
var loginName = TheApplication().LoginName();

if (loginName == "SADMIN") {
this.ActivateField("Type");
this.SetFieldValue("Type","Commercial");
}
}

Hit the Save button. Compile the Account Business Component by right-clicking on the Account
Business Component and choosing Compile Selected Object.

Open Client and test the code.


Scenario # 3

Business Component: Service Request


Where: Server Script
Scenario: A Service Request cannot be Closed untill all Activities
associated with it are marked as Done.

Lock the Service Project.

On the Service Request Business Component, right click and choose Edit Server Script. Choose
eScript as your language of scripting. On the PreSetFieldValue event, write the code below.

function BusComp_PreSetFieldValue (FieldName, FieldValue)


{
if (FieldName == "Status") {
if (FieldValue == "Closed") {
var vSRID = this.GetFieldValue("Id");
var vSRBO = TheApplication().GetBusObject("Service Request");
var vACTBC = vSRBO.GetBusComp("Action");

vACTBC.ClearToQuery();
vACTBC.SetViewMode(AllView);
vACTBC.ActivateField("Activity SR Id");
vACTBC.SetSearchSpec("Activity SR Id",vSRID);
vACTBC.ExecuteQuery();

var bIsRecord = vACTBC.FirstRecord();


while(bIsRecord) {
var actStatus = vACTBC.GetFieldValue("Status");
if (actStatus != "Done") {
TheApplication().RaiseErrorText("Not All
Activities are Closed");
return(CancelOperation);
}
bIsRecord = vACTBC.NextRecord();
}
}
}
return (ContinueOperation);
}

Hit the Save button. Compile the Service Request Business Component by right-clicking on the
Service Request Business Component and choosing Compile Selected Object.

Open Client and test the code.


Excercises

1. For Contact’s, Last Name and the First Name should not be the same.
(Hint: Contact BC, Server Script, Write Record Event)
2. If SADMIN logins in, whenever he queries on any of the Account views, show only
Accounts with the Status as Active
(Hint: Account BC, Server Script, PreQuery Event)

You might also like