Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Fix script to update all records in column

jho
Kilo Contributor

Hello,

I am trying to create a fix script that updates all records from a default value to 'Null'. I managed to update a record individually using the following script.

var enquirySysId='d2e94ff81b793050be465248274bcbcb,89e499d31b8df0106609cb7b1d4bcbbb'; // insert sys id here
var gr= new GlideRecord('x_mmco_streamline_enquiry');
gr.addQuery('sys_id',enquirySysId);
gr.query();
if(gr.next())
{
gr.priority ='NULL';
gr.update();
}

I would now like to use the script below to update all records but it does not look like any records are updating.

var gr= new GlideRecord('x_mmco_streamline_enquiry');
gr.query();
if(gr.next())
{
gr.setValue('priority','NULL');
gr.updateMultiple();
}

How do I get the script to update all records to 'NULL'?

1 ACCEPTED SOLUTION

Tony Chatfield1
Kilo Patron

Hi, updateMultiple() does not use query() or next() methods, as you are not iterating through a record set.
https://developer.servicenow.com/dev.do#!/reference/api/orlando/server/no-namespace/c_GlideRecordScopedAPI#r_ScopedGlideRecordUpdateMultiple?navFilter=updatemultiple
Try updating your code to mirror the SNC example

var gr = new GlideRecord('x_mmco_streamline_enquiry');
gr.setValue('priority','NULL');
gr.updateMultiple();

 

 

 

 

View solution in original post

1 REPLY 1

Tony Chatfield1
Kilo Patron

Hi, updateMultiple() does not use query() or next() methods, as you are not iterating through a record set.
https://developer.servicenow.com/dev.do#!/reference/api/orlando/server/no-namespace/c_GlideRecordScopedAPI#r_ScopedGlideRecordUpdateMultiple?navFilter=updatemultiple
Try updating your code to mirror the SNC example

var gr = new GlideRecord('x_mmco_streamline_enquiry');
gr.setValue('priority','NULL');
gr.updateMultiple();