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

Anil Lande
Kilo Patron

Hi,

Can you please share how these two tables are related and what is the criteria for Oldest open ticket?

And when you want to populate that information?

 

Thanks,

Anil Lande

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

Its a scoped application , where x_sts_mains is the parent table and x_sts_claims is the child table .

Parent table can have multiple child claims ticket...so i want to find out the age of the oldest Open claim ticket's age in days and display it on the field i.e Oldest open child ticket which is present on parent form.

 

Want to show on dispalying the form.

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

how are you determining the age of ticket?

are you tracking it based on closed - opened on child record?

what script did you start?

when should the field on parent get updated

Regards
Ankur

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

how are you determining the age of ticket? by 'sys_created_on'

are you tracking it based on closed - opened on child record?  Only for Open child tickets.

when should the field on parent get updated - the field Age of Oldest open child ticket (in days) should display on the parent form with the days count once the user open the form.