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

Not applicable

Hi Rohila

 

Never directly assign a value to a variable and call multipleUpdate()!

That will cause all records of the table to have the value changed whatever the query!!

Always use .setValue() together with updateMultiple()!

 

Please fix your comment or remove it before someone, for some reason, decides to use your way of updating the records and actually destroy data in the table!

 

Best regards

Nuno Agapito

Thank You Nuno, I modified the code.