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

@Shiva prasad 

Is your issue resolved?

If yes, feel free to mark correct so it ends up in resolved queue and also will be helpful for someone looking for similar queries.

Best Regards
Aman Kumar

Hello @Aman Kumar 

I am talking about state not about stage

i am confused what to do.

 

I know state is something that you need to close, also you need to set state as well, that's what I have mentioned in your other post.

STATE and STAGE both are fields on on your RITM form, both has to updated in order to the Request to be closed

Check the condiiton of the BR:

current.stage.changes() && (current.stage=='complete' || current.stage=='Request Cancelled' || current.stage == "closed_incomplete" || current.stage=="closed_skipped")

 

Just add the line as I have suggested above, it will work for you

Best Regards
Aman Kumar

Hello @Aman Kumar 

I updated the code as u mentioned. but it's not working for closed_complete. it's only working for 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.stage = "closed_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();
	}
})(current, previous);

@Shiva prasad 

Look closely its "completed" and not "closed complete"

       ritm.stage = "complete";//update stage on RITM as complete
  ritm.stage = "closed_incomplete";//update stage on RITM as incomplete

current.stage.changes() && (current.stage=='complete' || current.stage=='Request Cancelled' || current.stage == "closed_incomplete" || current.stage=="closed_skipped")

Feel free to mark correct, If I answered your query.

Will be helpful for future visitors looking for similar questions 🙂

 

Best Regards
Aman Kumar