Using a background script to fill a field on all values of a table

SC10
Kilo Guru

With a background script, I am trying to query all of the records of my dmn_demand table, and fill in a field with matching data from another field already present on each record.

This is the code that I have tried and didn't have work. Thought I'd reach out to the community for some pointers on where I am going wrong:

var gr = new GlideRecord('dmn_demand');

  1. gr.query();

while (gr.next()) {

  1. gr.autoSysFields(false);
  2. gr.u_task_for = gr.u_requestedfor;
  3. gr.update();

}

Thank you

1 ACCEPTED SOLUTION

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Shane,



Can you please confirm if field column name is u_requestedfor. I am assuming it should be u_requested_for.


Also add gr.setWorkflow(false); line before gr.update(); and try once.


View solution in original post

5 REPLIES 5

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Shane,



Can you please confirm if field column name is u_requestedfor. I am assuming it should be u_requested_for.


Also add gr.setWorkflow(false); line before gr.update(); and try once.


The addition of "gr.setWorkflow(false);" made it work correctlyy, thank you!



Could you please let me know exactly why adding that allowed it to work?


Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Shane,



While updating mass records we generally would like to fire notifications. In that case we will use the line gr.setWorkflow(false) which will turn of all BR's, notifications.


I understand that, but was wondering my script did not make any changes until I added your line of code to stop business rules from running on each record.