- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-17-2022 12:17 AM
I have a fix script through which i have to set the value of some ritms,but the value is not setting. can somone rectify my code?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-17-2022 12:24 AM
Hello @anayna you need to update two lines in your code
i have mentioned in comments of the script where ever i have updated the code
var arr = [];
var gr = new GlideRecord("sc_req_item");
gr.addEncodedQuery("state=2");
gr.query();
while(gr.next()) {
var count = 0;
var task = new GlideRecord("sc_task");
task.addQuery("request_item", gr.sys_id);
task.query(); // updated this to task.query(); from taskRec.query();
var totalCount = task.getRowCount();
while(task.next()){
if(task.active.toString() == 'false'){
count++;
}
}
if(count== totalCount && totalCount != 0){
var ab = arr.push(gr.getValue('number'));
gr.setValue('priority',4);
gr.update(); // added this line
}
gs.print(arr);
Hope this helps
Mark my answer correct if this helps you
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-17-2022 12:22 AM - edited 11-17-2022 12:27 AM
Hi,
After this line:
gr.setValue('priority',4);
you need to add
gr.update();
Also, I would recommend to check if it is entering the below loop, as getRowCount() doesn't allow you to iterate:
Please try and let me know if this helps?
Please make it correct if this solves your issue for other to make use it.
Thanks & Regards,
Vikrant Sharma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-17-2022 12:24 AM
Hello @anayna you need to update two lines in your code
i have mentioned in comments of the script where ever i have updated the code
var arr = [];
var gr = new GlideRecord("sc_req_item");
gr.addEncodedQuery("state=2");
gr.query();
while(gr.next()) {
var count = 0;
var task = new GlideRecord("sc_task");
task.addQuery("request_item", gr.sys_id);
task.query(); // updated this to task.query(); from taskRec.query();
var totalCount = task.getRowCount();
while(task.next()){
if(task.active.toString() == 'false'){
count++;
}
}
if(count== totalCount && totalCount != 0){
var ab = arr.push(gr.getValue('number'));
gr.setValue('priority',4);
gr.update(); // added this line
}
gs.print(arr);
Hope this helps
Mark my answer correct if this helps you
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-17-2022 12:43 AM
Hello Ananya,
Try adding gr.update() after seeting the state value at end also modify taskRec.query(); to task.query();
Thanks