- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2024 03:59 AM
Hello All,
Can anyone please help me how to acheive this.
i need to store diierence of actual end and actual start field value in total onhold time.
It is giving 1 hour 10minutes and 06 second.But it should give only 10 min 06 second.
Can anyone please help me how to get this correct value.
below is the before business rule i wrote.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2024 10:50 PM - edited 09-21-2024 10:54 PM
Hi @Mansi roy ,
Fields with data type - Time will append 1970-01-01 before the time value in UTC.
Ex: let us consider Actual Start : 11:38:19, it'll be 1970-01-01 06:08:19 (you can find this in XML).
if you want to set value to time field you've to use this format.
I made modifications to your code, It should work as desired.
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var actualStart = current.u_start;
var actualEnd = current.u_end;
// gs.info('Actual Start'+actualStart +'Actual End'+actualEnd);
var gdt1 = new GlideDateTime(actualStart);
var gdt2 = new GlideDateTime(actualEnd);
var diffIs = gs.dateDiff(gdt1,gdt2);
gs.addErrorMessage(diffIs);
var gdt= new GlideDateTime('1970-01-01 '+diffIs);
gdt.addSeconds(gdt.getTZOffset()/-1000);
gs.addErrorMessage(gdt);
current.u_time_diff= gdt;
// current.update();
})(current, previous);
Mark my response as helpful 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2024 04:22 AM - edited 09-20-2024 04:22 AM
Hi @Mansi roy ,
I tried the below code in the background script and it seems to work fine. Can you please try checking it.
var start=new GlideDateTime("2024-09-20 11:38:19"); //your start date
var end= new GlideDateTime("2024-09-20 11:48:25"); //your end date
var start_mill=start.getNumericValue(); //turning to milliseconds
var end_mill=end.getNumericValue();/turning to milliseconds
var diff=(end_mill-start_mill); //difference in milliseconds
var final_date=new Date(diff).toISOString(); //turning to date once again from milliseconds
gs.print(final_date); //printing the date and time
Please find the screenshot attached for the output which I received.
Please mark my answer "Helpful" and "mark as complete" if you feel that it has helped you in any way.
Thanks and Regards,
K. Sai Charan
Sr. ServiceNow Developer
Deloitte India
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2024 05:24 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2024 05:42 AM
May I know what error are you getting? Can you please share the screenshot?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2024 05:47 AM
I am not getting the value the actual on hold field.it is coming blank.