Update multiple records with background script

Dawid2
Giga Guru

I need to update couple of the records with the help of the background script. The field I need to update is a free text field, which = to value NAAM. I need to update it so it says NAM.

Here's the script I'm using but it's not working - anyone knows why?

var rg = new GlideRecord('incident');
rg.addQuery("u_alias1", "=", "NAAM");
rg.query();
while(rg.next){
rg.u_alias1="NAM";
rg.update();
}

1 ACCEPTED SOLUTION

Martin Ivanov
Giga Sage

try with

var rg = new GlideRecord('incident');
rg.addQuery("u_alias1", "=", "NAAM");
rg.query();
while(rg.next()){
rg.setValue('u_alias1','NAM');
rg.update();
}

View solution in original post

6 REPLIES 6

Martin Ivanov
Giga Sage

try with

var rg = new GlideRecord('incident');
rg.addQuery("u_alias1", "=", "NAAM");
rg.query();
while(rg.next()){
rg.setValue('u_alias1','NAM');
rg.update();
}

The problem was that you were missing the brackets after the .next() method.

Please makr Correct and Helpful. Thanks

Himanshu Gupta1
Mega Guru

Hi 

 

Please do you setworkflow(false) and autosysfield(false) as well so that it wil not trigger or update user that you doing something at backend


var rg = new GlideRecord('incident');
rg.addQuery("u_alias1", "=", "NAAM");
rg.query();
while(rg.next()){
rg.u_alias1="NAM";
rg.setWorkflow(false);
rg.autoSysFields(false);
rg.update();
}

Please mark it helpful and correct if your query get resolved

Best Regards

Himanshu Gupta

Voona Rohila
Tera Patron

Hi Dawid

Try this

var rg = new GlideRecord('incident');
rg.addQuery("u_alias1", "=", "NAAM");
rg.query();
rg.setValue('u_alias1',"NAM");
rg.updateMultiple(); 

https://community.servicenow.com/community?id=community_article&sys_id=53e36473dbd244502be0a851ca961...

 

you can also achieve this with no-coding using update-selected/update all option.

https://docs.servicenow.com/bundle/rome-platform-user-interface/page/use/using-lists/task/t_EditMult...