- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-30-2020 09:04 AM
Hello,
We have a catalog item that generates a REQ a little differently than the OOB way. When a REQ is created, it goes through an approval process first. Once the REQ is approved, an SCTASK and RITM gets created under the REQ. The SCTASK is not created under the RITM. My question is, when the SCTASK that is created under the REQ is closed, how can I also close the RITM and REQ or to make things more simple, how can I close all tickets once the SCTASK is closed?
Thanks!
*** EDITED ***
Here is an example of what I am talking about
As you can see when a REQ is created and approved, a RITM and SCTASK is also created. Within the RITM there is an additional SCTASK created. There is redundancy happening here. The users are working within the SCTASK being created on the REQ and not the RITM. If the SCTASK within the RITM is closed, it works as expected by closing the RITM and the REQ but not when the SCTASK in the REQ is closed.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-01-2020 08:24 AM
to close the RITM and other SC TASK for this REQ use this
Update the existing BR code with this
// get RITM for this REQ and close it
var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('request', current.request);
ritm.query();
if(ritm.next()){
ritm.state = 3;
ritm.update();
// close SC Task for this RITM
var taskRec = new GlideRecord('sc_task');
taskRec.addQuery('request_item', ritm.sys_id);
taskRec.addEncodeddQuery('stateIN-5,1,2');
taskRec.query();
while(taskRec.next()){
taskRec.state = 3;
taskRec.update();
}
// close the REQ
var req = current.request.getRefRecord();
req.state = 3;
req.update();
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
‎09-30-2020 10:50 AM
Since your workflow is on sc_request table, you can do this in your same workflow which creates SCTASK.
Regards,
Sachin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-30-2020 11:01 AM
If so, how do I set the value to the sctask that is created?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-30-2020 12:28 PM
When I created the scratchpad variable and captured the SYS_ID, it returned the SYS_ID of the REQ and not the SCTASK. This could be useful because then I can do as you mentioned above and query the REQ and RITM and close them out. How would I query the REQ and RITM and close them when the SCTASK (on REQ) is closed?
As you can see in the image, when on the SCTASK, the related ticket is not a RITM. It is a REQ.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-30-2020 10:38 AM
Assumption: request field on sc_task is populated
After update BR on sc_task
Condition: current.request != ''
Script:
var req = current.request.getRefRecord();
req.state = 3;
req.update();
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
‎09-30-2020 10:44 AM