- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2022 09:59 PM
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 .
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2022 12:35 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2022 12:35 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2022 12:54 AM
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 ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2022 01:09 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader