Need help for one of script for Business rule

Are Kaveri
Tera Contributor

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 ?

 

1 ACCEPTED SOLUTION

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();

 

 

View solution in original post

7 REPLIES 7

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();

 

 

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....

LinkedIn - Lets Connect

Sohail Khilji
Kilo Patron
Kilo Patron

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....

LinkedIn - Lets Connect