- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2024 10:35 AM
Hello Experts,
We want to calculate the request or change created between approval approved days calculation.
this is totally new requirement for us.
created new field on the approval table.
field name - "Open days"
field type - Date/time.
Requirement .
How to achieve the calculation created b/w approved kindly support.
Thanks!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2024 11:05 AM
Hi @akin9 ,
You need to create the custom field with the type as "Duration" in order to store the duration between approval created, action taken and update this field from a after business rule. I have implemented the solution in my PDI, attached the below screenshots for your reference.
Let me know in case if you have any further queries.
If the solution shared works for you, please "Accept as Solution" and mark " Helpful."
Thanks,
Gummagatta Harshavardhana
Dictionary Entry -
Business rule condition -
Business rule script -
.
var gdt1 = GlideDateTime(current.getValue('sys_created_on')); // get the request opened date and time
var gdt2 = GlideDateTime(current.getValue('sys_updated_on')); // get the request closed date and time
var duration = gs.dateDiff(gdt1.getDisplayValue(), gdt2.getDisplayValue(), false); // Calculate the difference bewtween opened and approved time
var grAppr = new GlideRecord('sysapproval_approver');
grAppr.addQuery('sys_id', current.getUniqueValue());
grAppr.query();
if (grAppr.next()) {
grAppr.u_approval_duration = duration; // update the duration field with the difference
grAppr.update();
}
Output -
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2024 10:34 AM
If the solution shared works for you, please "Accept as Solution" and mark " Helpful."
Thanks,
Gummagatta Harshavardhana
var gdt1 = GlideDateTime(current.getValue('sys_created_on')); // get the request opened date and time
var gdt2 = GlideDateTime(current.getValue('sys_updated_on')); // get the request closed date and time
// var duration = gs.dateDiff(gdt1.getDisplayValue(), gdt2.getDisplayValue(), false); // Calculate the difference bewtween opened and closed time
var schedule = new GlideSchedule();
schedule.load('090eecae0a0a0b260077e1dfa71da828'); // loads "8-5 weekdays excluding holidays" schedule
var duration = schedule.duration(gdt1, gdt2);
var grAppr = new GlideRecord('sysapproval_approver');
grAppr.addQuery('sys_id', current.getUniqueValue());
grAppr.query();
if (grAppr.next()) {
grAppr.u_approval_duration = duration; // update the duration field with the difference
grAppr.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2024 11:58 AM
Thank you very much for your Quick support, its working fine for me.