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

KalyaniDeshmukh
Tera Expert

Hi,

 

You can do is split 3 from the duration. Use this script for doing the same.

var actualDuration;

actualDuration =  duration.split(" ");  // duration which has value 3 minutes

var result  = actualDuration[0]; // should  have 3 as required

 

Kindly mark it Helpful.

 

the solution you provided  was working now. But everytime the duration cannot be in minutes ? how to handle this do i need to convert into minutes ?

@Hi @Are Kaveri : yes best way is to convert all in minutes, will be easy for other system to receive in same format that is in minutes.

 

Kindly mark my response Helpful.

 

Thanks.

@KalyaniDeshmukh Do you have any sample code for getting minutes in duration??