February 09, 2020

How to update bulk records in Siebel using eScript?

The best suggestion anyone can give to update records in bulk in Siebel is to use Siebel EIM. However sometimes developers don't have time to create EIM job, test it in lower environments and get it working in some days, and business can't wait for that long, And pesky admin team won't give developers the SQL access to production.



Then this is the last solution. Write a dirty little script and run it in business service simulator.

    var bo = TheApplication().GetBusObject("BO");
    var bc = bo.GetBusComp("BC");
    bc.ClearToQuery();
    bc.SetSearchExpr("Search Spec");
    bc.ExecuteQuery();
    var ret = bc.FirstRecord();
    while(ret) {
      bc.SetFieldValue("Field", "Value");
      bc.WriteRecord();
      bc.NextRecord();
    }
    bc = null;
    bo = null;

Easy, peasy ??? Well no..because Siebel compares modification number before updating record with modification number record was first queried. If some other process happens to update the record between that time you first query the records and updating the record then you will see following error.

Because we are updating bulk records,let's say 10K the time between query and update can be long enough for this error.
SBL-DAT-00523 - The Selected Record Has Been Modified by Another User since it was retrieved.
Then whats the workaround? How can we reduce chances of another process updating the records?? By Re-Querying the records before updating them. 😃

    var bo = TheApplication().GetBusObject("BO");
    var bc = bo.GetBusComp("BC");
    var bo1 = TheApplication().GetBusObject("BO");
    var bc1 = bo1.GetBusComp("BC");
    bc.ClearToQuery();
    bc.SetSearchExpr("Search Spec");
    bc.ExecuteQuery();
    var ret = bc.FirstRecord();
    while(ret) {
      bc1.ClearToQuery();
      bc1.SetSearchSpec("Id", bc.GetFieldValue("Id"));
      bc1.ExecuteQuery();
      if (bc1.FirstRecord()) {
        bc1.SetFieldValue("Field", "Value");
        bc1.WriteRecord();
      }
      bc.NextRecord();
    }
    bc1 = null;
    bo1 = null;
    bc = null;
    bo = null;

This way time difference between querying record and updating it will be smallest, thus chances of other processes updating record would be low.

 Happy Siebel 😃

1 comment :