Siebel - DeleteRecord Method in eScript

Let me take this opportunity to share a unique issue that I faced during one small requirement development.

Requirement: Contacts with a specific roles are created due a configuration miss in the EAI. As the product is live the fix can be put only after the root cause is found and change window is available. Till then these records needs to be deleted. As the number of records is huge deleting these records manually is a time consuming task and no back end deletion is allowed as the product is live. As a work around a client side BS would be developed to over come the problem.

Siebel  Version : 7.7

Below is the pseudo code

BusCom = "TechLabHelp"
With BusCom
               clear Query()
               Search for Contact with Role "TECHLABS"
               FirstRec = FirstRecord
               While (FirstRec)
                       FirstRec = DeleteRecord
               End While
End With

Hope pseudo code is simple and self explanatory. Now let me show how the Siebel eScript looked like.


.............

BusComp = "TechLabHelp"
With BusComp
{
    ClearToQuery();
    SetSearchSpec("Type", "TECHLABS");
    ExecuteQuery(ForwardOnly);
    var FirstRec=FirstRecord();
    while(FirstRec)
    {
     FirstRec = DeleteRecord();
     }
}
..................


Not sure why but the above code would always delete only one record form the query result. Also as a best practice and as said by Siebel Bookshelf NextRecord method cannot be used after DeleteRecord as the cursor is moved to next record by default. I was totally not sure if I had a way to resolve this. However logically it can be resolved by having one more While loop and keep the count of records, delete the records until count goes to zero. But Two while loops is not a good idea as it consumes a lot of resources.

So how did I resolve the issue is as below.


.............

BusComp = "TechLabHelp"
With BusComp
{
    ClearToQuery();
    SetSearchSpec("Type", "TECHLABS");
    ExecuteQuery(ForwardOnly);
    var FirstRec=FirstRecord();
    while(FirstRec)
    {
     FirstRec = DeleteRecord();
     //This did the trick. The Cursor would always be reset to First record and the deletion went fine.
    FirstRec=FirstRecord();
     }
}
..................

Its simple but took good amount of time to find the issue.

Will try to share similar posts going forward.

Comments

Post a Comment

Popular posts from this blog

How to call a Business Service from a PM/PR file in Siebel Open UI

Siebel Business Service Part-4