Close RITM and Request when all catalog tasks are closed

Samiksha2
Mega Sage

Hi All,

 

I have below requirement:

All Tasks are Closed Complete – RITM and Request Closed Complete.

All Tasks are Closed Incomplete – RITM and Request Closed Incomplete.

All Tasks are Closed Skipped – RITM and Request Closed Skipped.

 

If it is a mix, then:

If any are Closed Complete, then RITM and Request Closed Complete

Else RITM and Request Closed Incomplete

 

I tried to do with Flow designer but it is updating only one state i.e Closed Complete

Samiksha2_1-1695867951134.png

 

 

Please help me in the above logics in FD or with any script.

Thanks,

Samiksha

1 ACCEPTED SOLUTION

@Samiksha2 create another variable called "anyClosed" and in the for each step add an if condition, if task status is closed complete set anyClosed variable to true.

 

Then after the for loop your conditions will be like below,

 

if - anyClosed :: is :: true -- Set the status to Closed Complete

else if - first variable :: is :: closed complete -- Set the status to Closed Complete

else if - first variable :: is :: closed Incomplete -- Set the status to Closed Incomplete

else if- first variable :: is :: closed skipped -- Set the status to Closed Skipped

 

Please mark my answer helpful and accept as solution if it helped you 👍✔️

Thanks,
Anvesh

View solution in original post

13 REPLIES 13

Hey @Samiksha2 

 

Will the BR work for what you asked for in the condition below because I have the same requirement?

 

"If it is a mix, then:

If any are Closed Complete, then RITM and Request Closed Complete

Else RITM and Request Closed Incomplete"

Hi @elphilli,

Create another BR on After update and state changes.

(function executeRule(current, previous /*null when async*/ ) {
    var grSCTask = new GlideRecord('sc_task');
    grSCTask.addQuery('request_item', current.getValue('request_item'));
    grSCTask.addActiveQuery(); // added to check for active tasks
    grSCTask.query();
    if (!grSCTask.hasNext()) 
    {
        var closeCompleteCount = 0;
        var closeSkippedCount = 0;
        var closedIncompleteCount = 0;
        var closedOtherCount = 0;

        grSCTask = new GlideRecord('sc_task');
        grSCTask.addQuery('request_item', current.getValue('request_item'));
        grSCTask.query();
        while (grSCTask.next()) {
            if (grSCTask.getValue('state') == 3) {
                closeCompleteCount++;
            } else if (grSCTask.getValue('state') == 4) {
                closedIncompleteCount++;
            } else if (grSCTask.getValue('state') == 7) {
                closeSkippedCount++;
            } else {
                closedOtherCount++;
            }
        }

        var ritm = new GlideRecord('sc_req_item');
        //var req = ritm.request.getRefRecord();
        if (ritm.get(current.getValue('request_item'))) {
            //             if (closedIncompleteCount > 0 && closeCompleteCount == 0 && closedIncompleteCount == 0) {
            //                 ritm.setValue('state', 4); // ritm is closed incomplete
            //                 ritm.stage = "closed_incomplete";
            //                 ritm.update();
            //             } 
            if (closeSkippedCount > 0 && closeCompleteCount == 0 && closedIncompleteCount == 0) {
                ritm.setValue('state', 7); // ritm is closed skipped
                // req.state = 7;
                ritm.stage = "closed_incomplete";
                ritm.update();
            } else if (closeCompleteCount > 0 && closeSkippedCount == 0 && closedIncompleteCount == 0) {
                ritm.setValue('state', 3); // ritm is closed complete
                //req.state = 3;
                ritm.stage = "Completed";
                ritm.update();
            } else if (closeCompleteCount > 0 && closeSkippedCount > 0) {
                ritm.setValue('state', 3); // ritm is closed complete
                //req.state = 3;
                ritm.stage = "Completed";
                ritm.update();
            } else if (closeCompleteCount > 0 && closedIncompleteCount > 0) {
                ritm.setValue('state', 3); // ritm is closed complete
                //req.state = 3;
                ritm.stage = "Completed";
                ritm.update();
            } else if (closeSkippedCount > 0 && closedIncompleteCount > 0 && closeCompleteCount == 0) {
                ritm.setValue('state', 4); // ritm is closed complete
                // req.state = 4;
                ritm.stage = "closed_incomplete";
                ritm.update();
            }
        }
    }


})(current, previous);

Hope this will work.

 

Thanks,

Samiksha

@Samiksha2 

Hey, I have tried the BR above and that did not resolve the mixture of SCTASKs.

Hi @elphilli ,

It should work. Can you please show me your BR. I hope you have created two BRs.
Thanks,

Sam