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

First thing that you need to have an After update BR rule with condition work notes changes on sc_task table which passes those information in RIT and UR.

Another After update BR rule with condition state changes to closed on sc_task table which sets the RITM, Request and UR as closed.

Its pretty simple gliderecord query, for each table in the BRs, try it out and share with us.

Best Regards
Aman Kumar

To update the state of req and ritm i have done this and in the state mapping of universal request i have mentioned that when the state changes of its primary ticket (RITM), then universal request state will be changed. But the thing is Req state is not changing.

here is the written code : 

BR is after

condition is 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, next thing is, i have written code to update the worknotes of RITm and universal request , but i don't know how to update the universal request worknotes through code. so i need help over here too 

Here is the code :

BR is before insert or update

conditon is worknote/additional comments changes

(function executeRule(current, previous /*null when async*/) 
{
var com = "Catalog Task Comments for " + current.number + " : " + current.comments;
var v_gRITM = new GlideRecord('sc_req_item');
v_gRITM.addQuery('sys_id', current.request_item);
v_gRITM.query();
if (v_gRITM.next()) 
{
v_gRITM.comments= current.comments;
v_gRITM.work_notes= current.work_notes;	
v_gRITM.update();
}
})(current, previous);

For your 1st issue, the closure of RITM should result in closure of Request as well, that is administered by OOB BR "Close Parent if Required" and check the condition for these, probably you will have to make changes to your first script to update stage as well.

For your 2nd issue, you can find your way from Universal request using Primary ticket field on the form and using that you can pass on information from catalog task to UR

 

Best Regards
Aman Kumar

Hello @Aman Kumar 

I need your help for the below script. It's working fine for closing ritm if all the sc_task under it closed. along with that i need to close REQ. 

How and where can i add the script in the below mentioned script: 

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

I have already shared that, you have to follow "Close Parent if Required". no changes are required, so just have to additionally set the stage field of the ritm as complete or closed_incomplete.

 

Update the script in these lines:

	var ritm = current.request_item.getRefRecord();
	if(totalCount == closedCompleteCount){
		ritm.state = 3;
                ritm.stage = "complete";//update stage on RITM as complete
		ritm.update();
	}
	if(closedInCompleteCount > 0){
		ritm.state = 4;
                ritm.stage = "closed_incomplete";//update stage on RITM as incomplete
		ritm.update();
	}

 

Best Regards
Aman Kumar