Wednesday, February 15, 2012

Avoid duplicates using eScript.

To avoid duplication in Contact BC based on First Name and Last Name. If Firstname and LastName already exists then we have to raise a message.

BusComp_PreWriteRecord()
{

var oBO = TheApplication().GetBusObject(“Contact”);

var oBC = oBO.GetBusComp(“Contact”);

With(oBC)

{
SetViewMode(AllView);
ClearToQuery();
SetSearchSpec(“First Name”, this.GetFieldValue(“First Name”));
SetSearchSpec(“Last Name”, this.GetFieldValue("Last Name”));
ExecuteQuery(ForwardOnly);

if (FirstRecord())

{

TheApplication().RaiseErrorText (“Sorry this record exists”);

}
oBC = null;
0BO = null;
return(ContinueOpertion);

}

Compile and test. Please Note :
1. CancelOperation stops the execution of the underlying Siebel code associated with the event.
2. and no need to activate fields as it will be taken care by "SetSearchSpec".

ALSO Please Note:
About ExecuteQuery(ForwardOnly);
Use ForwardOnly Cursor Mode if you will traverse through the record set from FirstRecord using NextRecord and will not return to a previous record. If ForwardOnly cursor mode is not mentioned, it will be defaulted to ForwardBackward and to support this Siebel system has to create a Cache to maintain the entire record which would degrade the performance.

This is particularly true if you perform a look up or if you access a pick list.


Happy eScripting!!!!

Followers

Search This Blog