Easiest way to update multiple records from a table

mitzaka
Mega Guru

Hi SNC,

What will be the quickest way to go through all the records in a table and update a certain field in all of those records?

1 ACCEPTED SOLUTION

script based on the info you have provided ...



var gr = new GlideRecord('u_org_admin');


gr.query();


while(gr.next())


{


var referenceRecord = gr.u_org_admin.getRefRecord();


referenceRecord.u_is_org_admin = true;


referenceRecord.setForceUpdate(true);


referenceRecord.setWorkflow(false);


referenceRecord.update();


}


View solution in original post

12 REPLIES 12

Anurag Tripathi
Mega Patron
Mega Patron

Hi Dimitar,



Either run a background script or create an on demand scheduled job for this . Use setWorkflow(false) to make this query more optimum.


-Anurag

My table is called "u_org_admin" and the value I am trying to update is a true/false field on User form, named "u_is_org_admin". In the u_org_admin table I have a reference field called 'u_org_admin'.



I am trying with a background script of:



var gr = new GlideRecord('u_org_admin');


gr.addQuery('u_org_admin'); // because I want to get this field from all records in the table
gr.query();


while(gr.next())


{


gr.u_org_admin.u_is_org_admin = true; //here is where I try to set the value of the field


gr.setForceUpdate(true);


gr.setWorkflow(false);


gr.update();


}




However, it does not work, my values are still false.


script based on the info you have provided ...



var gr = new GlideRecord('u_org_admin');


gr.query();


while(gr.next())


{


var referenceRecord = gr.u_org_admin.getRefRecord();


referenceRecord.u_is_org_admin = true;


referenceRecord.setForceUpdate(true);


referenceRecord.setWorkflow(false);


referenceRecord.update();


}


You're a monster idude:) Agan that refRecord ,,,,,Kalaiarasan P Cheers!


You seriously need to learn this getRefRecord