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

hello can you show us how you build it as I am trying to put in a similar solution and it would be great to see an example of you -- if ---Else if

Ankur Bawiskar
Tera Patron
Tera Patron

@Samiksha2 

I will suggest to use BR here instead of flow because of different scenarios.

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

Hi @Ankur Bawiskar ,

I firstly tried with BR but I was unable to do the below condition:

If it is a mix, then:

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

Else RITM and Request Closed Incomplete

@Ankur Bawiskar 

Hey, how would you write this as a Business Rule?

Hi @elphilli ,

 

BR on sc_task table. After update. Condition- state changes

 var sct = new GlideRecord('sc_task');
    sct.addQuery('request_item', current.request_item);
    sct.query();
    var totalCount = sct.getRowCount();

    var sct1 = new GlideRecord('sc_task');
    sct1.addQuery('state','4');// change task state according to your requirement
    sct1.addQuery('request_item', current.request_item);
    sct1.query();
    var completedtotalcount = sct1.getRowCount();

    if (totalCount == completedtotalcount) {
        var ritm = current.request_item.getRefRecord();
		var req = current.request.getRefRecord();
              ritm.state = 4;//change ritm state according to your requirement
		ritm.stage="closed_incomplete";
		req= 7;//change request state according to your requirement
        ritm.update();
    }

 

Thanks,

Samiksha