If RITM state is closed complete then REQ should also closed complete

Shiva prasad t
Tera Guru

I need to update the REQ state to closed complete when RITM state is closed complete.

currently if state of sc_task is closed then RITM state is setting as closed complete.

So as well as RITM i need to closed Request also if RITM is closed.

Any help will be appreciated.

Thank you,

Shivprasad

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

then add the logic there itself where you are closing RITM

update as 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 = 3;
        req.update();
    }

})(current, previous);

Regards
Ankur

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

View solution in original post

12 REPLIES 12

Hmm, something is wrong can you share workflow where you are setting RITM to closed complete ? also all RITMs associate with REQ should be closed then only REQ will be closed. Is that what is happening ?

Please hit like and mark my response as correct if that helps
Regards,
Musab

Actually we are setting RITM to closed complete with BR. If all the sc_task under it closed complete then RITM will be closed complete.

This is the BR which is closing RITM

it's on sc_task table. after update one.

state is one of closed complete or closed incomplete

(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();
	if(totalCount == closedCompleteCount){
		ritm.state = 3;
		ritm.update();
	}
	if(closedInCompleteCount > 0){
		ritm.state = 4;
		ritm.update();
	}

})(current, previous);

And in our scenario we have only one RITM under REQ

so whenever state of RITM goes to closed complete then we need to set REQ state to closed complete 

@Shiva prasad 

Did you try the suggestion in an identical post?

 

Best Regards
Aman Kumar

You should do this from Workflow using Set activity, I guess the way BR is written might be causing conflict, howeover I see similar BR in my instance, I'm pasting code so see if that works in your case, I didn't write this code and don't prefer doing this way but since I found I'm sharing with you.

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

    var count = 0;
    var inTask = new GlideRecord('sc_task');
    inTask.addQuery('parent', current.parent);
    inTask.addQuery('state', '!=', '-53'); // check taska are open

    inTask.query();
    while (inTask.next()) {
        count = count + 1;
        //gs.addInfoMessage('count '+count);
    }
    //gs.addInfoMessage("count " + count);
    if (count == 0) {
        var ritm = new GlideRecord('sc_req_item');
        ritm.addQuery('sys_id', current.parent);
        ritm.query();
        if (ritm.next()) {
            ritm.state = '-53';  //Resolved
            ritm.update();
        }
    }
	var count1 = 0;
    var inTask1 = new GlideRecord('sc_task');
    inTask1.addQuery('parent', current.parent);
    inTask1.addQuery('state', '!=', '3'); // check taska are open

    inTask1.query();
    while (inTask1.next()) {
        count1 = count1 + 1;
        //gs.addInfoMessage('count '+count);
    }
    //gs.addInfoMessage("count " + count);
    if (count1 == 0) {
        var ritm1 = new GlideRecord('sc_req_item');
        ritm1.addQuery('sys_id', current.parent);
        ritm1.query();
        if (ritm1.next()) {
            ritm1.state = '-53';  //Closed Completed
            ritm1.update();
        }
    }






})(current, previous);

You should close RITM using set Activity in Workflow

find_real_file.png

 

 

Please hit like and mark my response as correct if that helps
Regards,
Musab

I am using flow designer not workflow