The CreatorCon Call for Content is officially open! Get started here.

When i update sctask state as closed complete it should update RITM and REQ/Universal state too?

Shiva prasad t
Tera Guru

1) when i update the state of sctask to any, then I need to update the state of RITM and REQ and Universal request too?

 2) When I update the work notes or additional comments of sctask it should update on RITM and on Universal request too?

1 ACCEPTED SOLUTION

It's working now like this

(function executeRule(current, previous /*null when async*/) {

    // Add your code here
    var closedCompleteCount = 0;
    var closedInCompleteCount = 0;
    var gr = new GlideRecord('sc_task');
    gr.addQuery('request_item', current.request_item); 
    gr.query();
    var totalCount = gr.getRowCount();
    while(gr.next()){
        if(gr.state == 3){
            closedCompleteCount++;
        }
        if(gr.state == 4){
            closedInCompleteCount++;
        }
    }

    var ritm = current.request_item.getRefRecord();
    var req = current.request.getRefRecord();
    if(totalCount == closedCompleteCount){
        ritm.state = 3;
        ritm.update();
        req.state = 3;
        req.update();
    }
    if(closedInCompleteCount > 0){
        ritm.state = 4;
        ritm.update();
        req.state = 4;
        req.update();
    }

})(current, previous);

View solution in original post

22 REPLIES 22

Mohit Kaushik
Mega Sage
Mega Sage

Hi Shiva,

You can write a Business Rule on sctask table, which will help you update the RITM, REQ and universal request's state also. May be below script can help:

Business Rule:

When : After update, condition: state is changed

Script:

var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('sys_id','request_item');
ritm.query();
if(ritm.next)
{
ritm.state = 4; // which ever number you want to update for your state field value;
ritm.update();
}

// Update Request state:
var req = new GlideRecord('sc_request');
req.addQuery('sys_id','request');
req.query();
if(req.next)
{
req.state = 4; // which ever number you want to update for your state field value;
req.update();
}

 

Similarly you can update the script accordingly for other scenarios as well.

 

Please mark this as correct and helpful if it resolved the query or lead you in right direction.

Thanks,
Mohit Kaushik
Community Rising Star 2022

Thanks,
Mohit Kaushik
ServiceNow MVP (2023-2025)

Hello @Mohit Kaushik 

Your code is not working.

My Scenario is like when ever we close the sc_task, then RITM and REQ both will also be closed.

That means, if we changed sc_task state to closed complete then RITM & REQ states will also be closed complete.

If sc_task state is Closed incomplete then RITM & REQ state will also be closed incomplete

 

Aman Kumar S
Kilo Patron

Explain your scenario, are you trying to automate this or you are asking whether it should work that way?

Best Regards
Aman Kumar

My scenario is like, along with REQ , Universal ticket is also creating. below are my requirements : 

1. When ever we update the work notes of sc_task , it should automatically appear on RITM worknotes and universal request work notes too.

2. when ever we change the sc_task state to closed complete the ritm state also same and aswell as REQ and universal request state also same.

I am not trying to automate, but it should work that way.