How to bring the age of oldest ticket created in the list of child task (x_sts_claims) to one of the fields in Parent Ticket (x_sts_mains) . Please suggest

Mishu
Tera Expert

How to bring the age of oldest ticket created in the list of child task (x_sts_claims) to one of the fields[Age of Oldest open child ticket ]  in Parent Table(x_sts_mains) . Any help would be appreciated .

1 ACCEPTED SOLUTION

Hi,

keep BR on parent table

Display

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

	// Add your code here
	var gr = new GlideRecord("x_sts_claims");
	gr.addQuery('status','open'); // give correct field name and value to check
	gr.orderBy('sys_created_on');
	gr.addQuery("parent",current.getUniqueValue()); // give correct parent field
	gr.setLimit(1);
	gr.query();
	if (gr.next()) {
		var nowTime = new GlideDateTime();
		var childTime = new GlideDateTime(gr.sys_created_on);

		var dur = GlideDateTime.subtract(childTime, nowTime);
		var days = parseInt(dur.getNumericValue()/86400000);

		current.fieldName = days; // give correct field name here
	}

})(current, previous);

Regards
Ankur

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

View solution in original post

12 REPLIES 12

Hi,

keep BR on parent table

Display

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

	// Add your code here
	var gr = new GlideRecord("x_sts_claims");
	gr.addQuery('status','open'); // give correct field name and value to check
	gr.orderBy('sys_created_on');
	gr.addQuery("parent",current.getUniqueValue()); // give correct parent field
	gr.setLimit(1);
	gr.query();
	if (gr.next()) {
		var nowTime = new GlideDateTime();
		var childTime = new GlideDateTime(gr.sys_created_on);

		var dur = GlideDateTime.subtract(childTime, nowTime);
		var days = parseInt(dur.getNumericValue()/86400000);

		current.fieldName = days; // give correct field name here
	}

})(current, previous);

Regards
Ankur

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

Its working fine but just a question , when i click on created column of list view of child table it shows me 3 days ago , but as per script it is setting 2 days in the field . What is the reason ?

 

 

Hi,

possibly because of timezone

Glad to know that my script worked.

Please mark my response as correct and helpful to close the thread.

Regards
Ankur

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