- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2024 10:43 PM
Hi
I have below requirement.
we have to calculate the difference between updated and created date .
var start_time = new GlideDateTime(grTaskSla.getValue('start_time'));
var end_time = new GlideDateTime(grTaskSla.getValue('end_time'));
var duration = GlideDateTime.subtract(start_time, end_time);
return duration.getDisplayValue();
In duration i am getting duration = updated - created = 3 minutes.
Since this field is integrated with other system. they set length as 3 . It was not accepting.
How to send 3 instead of 3 minutes ?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2024 12:48 AM
Hi @Are Kaveri
Try this
var duration = new GlideDateTime(current.glidefieldonform.getValue()); // getting duration and converting to GlideDateTime duration = duration.getNumericValue()/1000/60; // calculating the total duration in minutes gs.log('Duration in minutes is: ' + duration); current.fieldtobepopulated = duration.toString();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2024 12:48 AM
Hi @Are Kaveri
Try this
var duration = new GlideDateTime(current.glidefieldonform.getValue()); // getting duration and converting to GlideDateTime duration = duration.getNumericValue()/1000/60; // calculating the total duration in minutes gs.log('Duration in minutes is: ' + duration); current.fieldtobepopulated = duration.toString();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2024 11:50 PM
I belive it will always be in minuts like 10min 100min 1000min etc...
First you got to Decide what format the couter system is expecting like 0.10Hrs or 1.40Hrs etc.. or 00:10:56 etc..
Based on the needs you can convert the time to required formats...
I hope this helps too...
🙂
☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2024 10:54 PM - edited 02-03-2024 11:00 PM
Hi @Are Kaveri ,
I belive you need this for integration. You can push the return value in an array and retrive only numbers from the string and conctinate +'min' with the number returned. Use substr (0,2) to get the first 3 char +'min'
Ex: 3 Min & 34 Min or 451 Min (It has to work for all 3 char )
I hope this help....
var start_time = new GlideDateTime(grTaskSla.getValue('start_time'));
var end_time = new GlideDateTime(grTaskSla.getValue('end_time'));
var duration = GlideDateTime.subtract(start_time, end_time);
var num = duration.split(' ');
var r_num = num[0] + ' Min';
return r_num ;
☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....