- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2023 10:37 PM
Hi Team,
The 'duration' is giving an output of 'undefined' for the below code.
var scTask = '94af260e870bb1d04512ed7e0ebb3508';
gs.info("Task: " + scTask);
var grtaskSla = new GlideRecord('task_sla');
grtaskSla.addQuery('task', scTask);
grtaskSla.setLimit(1);
grtaskSla.query();
if (grtaskSla.next()) {
var endTime = grtaskSla.getValue('end_time');
}
var gdt = new GlideDateTime(endTime);
var hours = 60 * 60 * 8;
var newEndTime = gdt.getDisplayValue();
gs.info("End Time: " + newEndTime);
var acceptTime = '2023-12-13 13:21:07';
gs.info("Accept Time: " + acceptTime);
//var diff = GlideDateTime.subtract(newEndTime, acceptTime);
// var diff = new GlideDateTime();
var diff = gs.getDiff(newEndTime, acceptTime, false);
gs.info("Duration: " + diff);
Thanks and Regards,
Saurabh Chatterjee
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2023 11:18 PM
Hello @chatsaurav19
Can you replace this code
var hours = 8 * 60 * 60; // 8 hours in seconds
gdt.addSeconds(hours);
with the below code and let me know if still there is an issue or not?
var hours = 8;
gdt.addHours(hours);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2023 10:38 PM
*** Script: Task: 94af260e870bb1d04512ed7e0ebb3508
*** Script: End Time: 2023-12-13 13:21:56
*** Script: Accept Time: 2023-12-13 13:21:07
*** Script: Diff: undefined
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2023 11:00 PM
Hi @Aniket Thank you for your reply but I see that the 'end_time' value has changed and duration is incorrect:::
*** Script: Task: 94af260e870bb1d04512ed7e0ebb3508
*** Script: End Time: 2023-12-13 05:21:56
*** Script: Accept Time: 2023-12-13 13:21:07
*** Script: Duration: 23 Hours 59 Minute
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2023 11:18 PM
Hello @chatsaurav19
Can you replace this code
var hours = 8 * 60 * 60; // 8 hours in seconds
gdt.addSeconds(hours);
with the below code and let me know if still there is an issue or not?
var hours = 8;
gdt.addHours(hours);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2023 10:45 PM
Hello @chatsaurav19
I have not tested but you can try the below code and let me know if you still facing the issues or not
var scTask = '94af260e870bb1d04512ed7e0ebb3508';
gs.info("Task: " + scTask);
var grtaskSla = new GlideRecord('task_sla');
grtaskSla.addQuery('task', scTask);
grtaskSla.setLimit(1);
grtaskSla.query();
if (grtaskSla.next()) {
var endTime = grtaskSla.getValue('end_time');
gs.info("End Time: " + endTime);
var gdt = new GlideDateTime(endTime);
var hours = 8 * 60 * 60; // 8 hours in seconds
gdt.addSeconds(hours);
var acceptTime = new GlideDateTime('2023-12-13 13:21:07');
gs.info("Accept Time: " + acceptTime);
var diff = GlideDateTime.subtract(gdt, acceptTime);
gs.info("Duration: " + diff.getDisplayValue());
} else {
gs.info("No task_sla record found for task: " + scTask);
}
Mark ✅Correct if this solves your issue and also mark 👍Helpful if you find my response worthy based on the impact.
Regards,
Aniket