Why background script update only one record.

Tarasingh26
Tera Expert

Hi All,

 

I am trying to update thousand record using background script. Script is working fine but it updates only one record instead of thousand. Please see the code in attachment and provide solutions, if anyone faced this type of issue.

 

Thanks,

Tara Singh 

20230703_180517.jpg

3 ACCEPTED SOLUTIONS

Hi @Tarasingh26 ,

updateMultiple() doesn't work in scoped application, would suggest using standard update() function here, it should work just fine.

 

 

Best Regards
Aman Kumar

View solution in original post

Aman Kumar S
Kilo Patron

Hi @Tarasingh26 ,

updateMultiple() doesn't work in scoped application, would suggest using standard update() function here, it should work just fine.

 

Best Regards
Aman Kumar

View solution in original post

Riya Verma
Kilo Sage
Kilo Sage

Hi @Tarasingh26 ,

 

Hope you are doing great.

 

Instead of using update multipe use update function. also please try usig below script :

 

var gr = new GlideRecord("sn_risk_advanced_legal_entities");
gr.query();

while (gr.next()) {
  var gr1 = new GlideRecord("cmn_cost_center");
  gr1.addQuery('u_gl_company_code', gr.u_entity_code);
  gr1.setLimit(100);
  gr1.query();

  while (gr1.next()) {
    gr1.u_legal_entity = "ABC";
    gr1.setWorkflow(false);
    gr1.update();
  }
}

 

 
 
Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.
Regards,
Riya Verma

View solution in original post

12 REPLIES 12

@Tarasingh26 

which table you need to update cost center or risk?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

I want to update cost centre table based upon GL company code and legal entity field . GL company code in table 1 = Legal entity field in another table2.

Hi @Tarasingh26 ,

updateMultiple() doesn't work in scoped application, would suggest using standard update() function here, it should work just fine.

 

 

Best Regards
Aman Kumar

Aman Kumar S
Kilo Patron

Hi @Tarasingh26 ,

updateMultiple() doesn't work in scoped application, would suggest using standard update() function here, it should work just fine.

 

Best Regards
Aman Kumar

Thanks Aman Kumar. It is also working. Thanks for help. Really struggled with this issue in past few days.