Sandaru1
Tera Expert

Following are two bulk update scripts that can be reused.

If record bulk is bigger than 5000

var gr = new GlideRecord('table_name');   
gr.setLimit(100); //will update 100 records at a time
gr.addEncodedQuery('ADD QUERY');  // Add query
gr.query();   
while(gr.next())   
   {   
   gr.short_description = gr.short_description+' :Closed By a Script'; 
   /*
     SET OTHER PARAMETERS HERE
 */  
   gr.setWorkflow(false); //Will not fire BR & email notifications   
   gr.update();   
   }  

If you need it with a rollback option (Recommended for bulks less than 5000)

var gr = new GlideRecord("table_name");
gr.addEncodedQuery('ADD QUERY'); 
   /*SET PARAMETERS HERE
    i.e : gr.setValue('state', 5);
   */  
gr.setWorkflow(false); //Will not fire BR & email notifications  
gr.autoSysFields(false);  // Do not update sys_updated_by, sys_updated_on, sys_mod_count, sys_created_by, and sys_created_on
gr.updateMultiple();

 

Comments
WP2
Kilo Guru

How do you bulk update field on SCTask with the value of a field from RITM. E.g I have over 5000 SCTask records that have blank company field however, I want to copy over the data from the company field on the RITM.

Martin Ivanov
Giga Sage
Giga Sage

 

@WP2 

var grScTask = new GlideRecord('sc_task');
grScTask.addNullQuery('company');
grScTask.query();

while (grScTask.next()){
grScTask.setValue('company', grScTask.request_item.company);
grScTask.update();
}

 

 

Please mark Correct and Helpful. Thanks!

WP2
Kilo Guru

Thank you @Martin Ivanov It worked!

Fabricio4
Mega Sage

This is such a wonderful tip. Thanks!

 

Version history
Last update:
‎08-12-2022 05:33 AM
Updated by: