How to set closure(closed_at, closed by, duration and business durtion) for Active is false RITMs?

raj99918
Tera Contributor

Hi ,

 

I have old records of RITM which having closer details were null even though active is set to false so I need to set those fields (closed_at, closed by, duration and business durtion) How can I achieve it through fix script 

 

Thanks

6 REPLIES 6

OlaN
Giga Sage
Giga Sage

Hi,

Why does it need to be a fix script? You could also create a Flow that sets these values.
It should be fairly easy, no coding required.

raj99918
Tera Contributor

Hi @OlaN ,

 

Just want to know from Fix script point of view can you please let me know the solution

Sure.

Something like this might work, be sure to test the script and expected outcome, before running in production.

var ritmGR = new GlideRecord('sc_req_item');
ritmGR.addEncodedQuery('your encoded query here');
ritmGR.query();
while (ritmGR.next()){
	ritmGR.setValue('field name goes here', 'data to set goes here');
	// repeat above line for each field that needs to be set

	ritmGR.setWorkflow(false); // prevent running other business rules and flows
	ritmGR.autoSysFields(false); // prevent setting the sysfields when an update happens
	ritmGR.update();
}

 

mihirlimje867
Tera Guru

Hello @raj99918 ,
I hope this script functions will help you to calculate the duration.

 

if (current.state != 'closed_complete' && current.state != 'closed_abandoned') {
		current.closed_at = null;
		current.duration = null;
	}
	else {
		var opened_at = current.opened_at.dateNumericValue();
		if (current.closed_at.nil() || current.state.changes()) {
			current.closed_at = new GlideDateTime();
		}
		var closed_at = current.closed_at.dateNumericValue();
		current.duration = new GlideDuration(closed_at-opened_at);
	}

 

 

calDateDiff(String, String, boolean)

 

Calculate the difference between two dates using the default calendar.

 

 

 

dateDiff(String, String, boolean)

 

Calculates the difference between two dates. This method expects the earlier date as the first parameter and the later date as the second parameter; otherwise, the method returns the difference as a negative value.

These functions will help you.


Please hit the helpful button.
Thank you.