gr.update() not updating all records

Anubhuti
Tera Expert

Hi All,

I am trying to update the work notes of multiple task records, but only one record is getting updated.

Below is the script I am using:

var gr = new GlideRecord('tablename');
gr.addQuery('parent',current.sys_id);
gr.addEncodedQuery('stateNOT IN3,7');
gr.query();
while(gr.next()) {
gr.work_notes = "comments";
gr.update();
}
}

When running it as background script, I am getting the below mentioned error and when I am removing gr.update() i am not getting any error:

Cannot find function getLocation in object com.glide.script.fencing.ScopedUser@@@@@@
Has anybody experienced similar issue?

1 ACCEPTED SOLUTION

Anubhuti
Tera Expert

Hi All,

 

Thanks for your response.

As only one record was getting updated, at first I stored all the sysid in one array and then updated the work notes in another for loop and its working fine.

var arr =[];
var gr = new GlideRecord('tablename');
gr.addQuery('parent',current.sys_id);
gr.addEncodedQuery('stateNOT IN3,7');
gr.query();
while(gr.next()) {
arr.push(gr.sys_id.toString());
}

for(var i =0; i<arr.length; i++){
var gr = new GlideRecord('tablename');
gr.addQuery('sys_id',arr[i].toString());
gr.query();
if(gr.next()) {
gr.work_notes = "comments";
gr.update();
}
}

View solution in original post

13 REPLIES 13

Priyanka Gupta
Mega Guru

Hi Anubhuti,

In your script, you are passing one sys_id, current.sys_id which is why only one record is getting updated. You can make an array of sys_ids and use a for loop to loop thru each sys_id and update the work notes.

Regards,

Priyanka

I am passing the single sys_id of parent of the child task records.

Jon Ulrich
Kilo Guru

You may be getting hung up on an error in some business rule. You can skip running all business rules by adding gr.setWorkflow(false); inside your while before the update.

I am running it in background script there also its giving me the same error.