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

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);

You are force closing it and not following OOB BR, you could have easily hardcoded it and even I could have suggested that, but you are building an unnecessary update and force closing the request and it is not the right approach in my view, but revisit this, once you gain more ideas how to incorporate OOB functionality with your process

Best Regards
Aman Kumar

Mark Manders
Mega Patron

Since you can have multiple tasks to fulfill 1 request, it would be strange to close the request as soon as a task is closed. You need logic behind this. Please elaborate on what you are trying to achieve. What is your use case?

If my answer helped you in any way, please then mark it as helpful.

Mark


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

my scenario is like , if we have multiple sc_task (or) if we have only one sc_task under one ritm, if all the sc_task state is closed complete then only ritm state is closed complete otherwise it should remain in closed incomplete.

And one more thing i need to mention here is that we have universal request too.

that means along with Req and ritm we need to update universal request too

 

fgdfgdrg dgdrgd
Kilo Explorer

When I update the paintings notes or additional comments of sctask it should update on RITM and on Universal request too?  Cow Squishmallows