- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2022 07:06 AM
Hi team,
in the workflow i need to check the catalog task state.
the user is set to state 'delivered' in the catalog task , i want automatically update the catalog state as closed complete.
i have tried with the run script in the workflow activity with the below script
var gr = new GlideRecord('sc_task');
gr.addQuery('request_item', current.getUniqueValue());
gr.addQuery('state', '8');
gr.query();
while(gr.next()){
gr.setValue('state', '3');
gr.setWorkflow(false); //Set this value if you don't want any scripts to be triggered after the update
gr.update();
}
but its not working for me.
can someone please help me with script.
Regards,
chinna
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2022 08:03 PM
HI
Please use the below modified script:
var gr = new GlideRecord('sc_task');
gr.addQuery('request_item', current.sys_id);
gr.addQuery('state',8);
gr.query();
while(gr.next()){
gr.state = 3;
gr.setWorkflow(false); //Set this value if you don't want any scripts to be triggered after the update
gr.update();
}
Also if this does not works then can you run the below script in background and see what result are getting printed:
Navigate to Background Script module and execute below script and see what is getting printed for below script:
var gr = new GlideRecord('sc_task');
gr.addQuery('request_item', current.sys_id);
gr.addQuery('state',8);
gr.query();
gs.info('Row Count' + gr.getRowCount());
while(gr.next()){
gr.state = 3;
gr.setWorkflow(false); //Set this value if you don't want any scripts to be triggered after the update
gr.update();
}
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2022 07:10 AM
Hi,
are you sure the query for state = 8 is working fine and giving you records?
are you setting correct value for state 3
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2022 09:01 AM
Hi
thanks for the help in the workflow what exactly
iIn the wait for condition am checking the state values with the below script
var rec = new GlideRecord('sc_task');
rec.addQuery('request_item', current.getValue('sys_id'));
rec.addQuery('state','NOT IN','3,4,7');
rec.query();
if(rec.hasNext()){
answer = false;
}
else{
//Continue
answer = true;
}
if the state values is "open,workin progress and closed skipped), i dont want to move the catalog task forward.
and then am checking the state ' delivery' in the run script and trying to set the values.
var gr = new GlideRecord('sc_task');
gr.addQuery('request_item', current.getUniqueValue());
gr.addQuery('state', '8');
gr.query();
gs.log('TaskCount' +gr.getRowCount());
gs.log('RITM Sysid' +current.getUniqueValue());
while(gr.next()){
gs.log('InsideWhile' +current.state);
gr.setValue('state', '3');
gr.setWorkflow(false); //Set this value if you don't want any scripts to be triggered after the update
gr.update();
}
as you suggested i have tried with logs, but it returning (row count is :0).
can you please helpme what exactly i hav edone wrong here.
Regards,
Chinn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2022 07:48 PM
Hi
can you please help me with above requirement.
Thanks,
chinna

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2022 07:20 AM
Hi
Code seems fine. Try adding some logs to verify if its going inside while something like below
Also recheck what Ankur is saying.
var gr = new GlideRecord('sc_task');
gr.addQuery('request_item', current.getUniqueValue());
gr.addQuery('state', '8');
gr.query();
gs.log('TaskCount' +gr.getRowCount());
gs.log('RITM Sysid' +current.getUniqueValue());
while(gr.next()){
gs.log('InsideWhile' +current.state);
gr.setValue('state', '3');
gr.setWorkflow(false); //Set this value if you don't want any scripts to be triggered after the update
gr.update();
}
Check in logs table post that for these messages.
Thank you
Prasad