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

There might be a business rule which might be aborting the change. Please check for the same.


Let me know if you have any questions.