Revert back the state of RITM to its previous state
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2018 11:40 AM
Hi Everyone,
I need some help here,
actually a bunch of RITM(requested item) got updated to closedskipped state from its initial state via an unwanted script.
I commented out that script and wanted to revert back the state to their previous state from closed skipped.
FYI - we developed functionality of workflow cancellation on closedskiped state. we need to activate workflow too.
Help would be really appreciated.
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-05-2018 02:18 AM
Few links that can help you
https://community.servicenow.com/community?id=community_question&sys_id=3e998ba5db5cdbc01dcaf3231f9619ad
https://community.servicenow.com/community?id=community_question&sys_id=649ccfa5db9cdbc01dcaf3231f961961
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-05-2018 03:48 PM
Hi Kalai,
After long time, I'm glad to see you !
Actually, am able to reopen the workflow and update the sate of RITM to previous state but the only hurdle is am not able to update the state of task to what it was previously. The state of task getting updated to open which is not suppose to be, it should be previous state instead of open
I attached my code, could you please have a glance
var ritm=new GlideRecord('sc_req_item');
ritm.addQuery('number','IN','RITM0092371,RITM0092767');//pass in comma separated RITM numbers in the last attribute on this line
ritm.query();
while(ritm.next()){
gs.print(ritm.number);
var ritmupdate=new GlideRecord('sys_audit');
ritmupdate.addQuery('tablename','sc_req_item');
ritmupdate.addQuery('fieldname','state');
ritmupdate.addQuery('newvalue','7');
ritmupdate.addQuery('documentkey',ritm.sys_id);
ritmupdate.query();
while(ritmupdate.next()){
gs.print(ritmupdate.sys_id);
ritm.state=ritmupdate.oldvalue;
ritm.update();
}
var task=new GlideRecord('sc_task');
task.addQuery('request_item',ritm.sys_id);
task.query();
while(task.next()){
var taskupdate=new GlideRecord('sys_audit');
taskupdate.addQuery('tablename','sc_task');
taskupdate.addQuery('fieldname','state');
taskupdate.addQuery('newvalue','IN','3,4');//checking task status // 3- closed complete and 4- closed incomplete
taskupdate.addQuery('documentkey',task.sys_id);
taskupdate.query();
while(taskupdate.next()){
gs.print(taskupdate.sys_id);
task.state=taskupdate.oldvalue;
task.update();
}
}
new Workflow().restartWorkflow(ritm,true);
}
Thanks