- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2019 03:41 AM
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?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2019 11:46 PM
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();
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2019 11:13 PM
HI,
Use below code:
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.setWorkflow(false);
gr.update();
}
}
From wherever you run script the BR will trigger on that tables. So use setWorkflow(false);
Thanks,
Ashutosh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2019 11:46 PM
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();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2019 11:53 PM
Just a sidenode
That is far from recommended duo to performance impact.
Why dont you try to figure out whats wrong ?
What happens if you update another field on multiple records at a time ? Does that work ?
You can easily test it from the list first. - if it works try through the script you created
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2019 12:25 AM
Yes, I agree this is not recommended and may impact performance as well but I tried everything possible.
As soon as I add gr.update() error occurs.
One of the reason could be that I am working in a scoped application.
That is why I asked if anyone is aware of the error I got.
I will try to find out the cause for the error ,this is just a temporary fix.
If anyone get to know about the same please update all of us.