- 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-16-2022 11:46 PM
I tried with display BR on child table with condition as State is Open :
var now = new GlideDateTime();
var created = new GlideTimeDate(current.sys_created_on);
var duration = GlideTimeDate.subtract(created, now);
var value = (duration.getNumericValue() / 1000);
var days = value / 86400;
var aud = new GlideAggregate('x_sts_claims');
aud.addQuery('status' , 'open');
aud.addQuery('parent, current.parent);
aud.addAggregate('MIN', days);
aud.setGroup(false);
aud.query();
while (aud.next()) {
var gr = new GlideRecord ('x_sts_mains');
gr.addQuery('sys_id' , current.parent);
gr.query();
if(gr.next())
{
gr.age_of_child_ticket =aud.getAggregate('MIN', days);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2022 11:47 PM
Hi,
you can use display business rule on parent table
1) query child table with this parent and use orderBy('sys_created_on') to get oldest child
I assume your field "Age of Oldest open child ticket" is string type
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var gr = new GlideRecord("x_sts_claims");
gr.addQuery("state", "2"); // give correct query to indicate open state
gr.orderBy('sys_created_on');
gr.addQuery("parent", current.getUniqueValue());
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);
current.fieldName = dur.getDisplayValue();
}
})(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:03 AM
The output or the aging your script is returning is in days ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2022 12:18 AM
Hi,
you want in exact days ?
BR would be on parent table and not child
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:21 AM
yes I want to show the aging in days . The current script is not returning the correct age in days.