How to close RITM and REQ from an SCTASK

mkader
Kilo Guru

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 

find_real_file.png

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.

1 ACCEPTED SOLUTION

@mkader 

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

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

28 REPLIES 28

@mkader 

Did you tried the provided solution, Please keep posted for more help?

Regards

Yash Agrawal

@Yash Agrawal - I tried what Ankur told me to do to close the REQ and it worked, but the RITM in the 2nd workflow is still open. If you read the thread between me and Ankur you will have more details. How can I close the RITM now? If the RITM is closed then closing the REQ will not be needed because there is a process that automatically closes the REQ when the RITM is closed.

Pooja Mallikarj
Kilo Sage

Hi,

You need to write after update business rule on sc_req_item table.

Make the condition as state is Closed complete

write below lines of code.

var gr=new GlideRecord('sc_task');
gr.addActiveQuery();
gr.addQuery('request_item',current.sys_id);
gr.query();
while(gr.next())
{
gr.state='3';     //value of closed complete
gr.request.state = '3';
gr.update();
}

Hope it helps for you.


Thanks,

Pooja M

@Pooja Mallikarjun - Thanks for your response. The problem with this is I need to grab the SCTASK related to the REQ. How can I do that? This approach works if the RITM is created in the REQ and the SCTASK is created in the RITM.

Again I have a duplicate process that we are not planning on removing for some reason.

Workflow 1: Creates a RITM and SCTASK within the REQ

Workflow 2: Creates an SCTASK within the REQ

Please see the screenshot I have provided to Yash