Sync REQ state to the RITM state

Andrew Meza
Tera Expert

I'm not too great on scripting (newbie) as some background context. The way we have our instance configured we have 1 REQ to 1 RITM. Is there a way to look at all of the RITMs in the past and update the parent request to match the state of the RITM?

 

ex.) I have 30 closed complete RITMs but when I look at the parent request, they're all "Open". I want some mechanism that will see the older Closed Complete RITM and update the parent task to Closed Complete also.

 

I want this done for the closed complete, closed incomplete, and closed skipped states. Any thoughts on how I can go about this? 

2 REPLIES 2

Harshal Aditya
Mega Sage
Mega Sage

Hi @Andrew Meza ,

 

Hope you are doing well.

 

You need to run a one time fix/background script. Please refer the below example.

 

Please first test the same in the lower environment

 

var closeRitm = new GlideRecord("sc_req_item");
closeRitm.addEncodedQuery("active=false^request.active=true");// Adding encoded query if request item is active false (closed) and request is active true (open)
closeRitm.query();
while(closeRitm.next()){
	
	var setRequest = new GlideRecord("sc_request");
	setRequest.get(closeRitm.request);
	if(closeRitm.state == 3){
		setRequest.request_state = "closed_complete";
setRequest.update()
	}
	else if(closeRitm.state == 4){
	setRequest.request_state = "closed_incomplete";
setRequest.update()
	}
	else if(closeRitm.state == 7){
	setRequest.request_state = "closed_skipped";
setRequest.update()
	}
}

 

Please mark this response as correct or helpful if it assisted you with your question.

Regards,
Harshal

Thank you Harshal, I ran the script and this is the log it gave me back. I dont see any changes to my REQ.