script was not working

Ak8977
Tera Expert

Hello all,
I have written a business rule for one case, in that script I have written the following logic but it was not working. The following is the scenario- 
there are two fields in utc_start_time and utc_end_time. I want the difference between the start time and endtime in  numeric value(minutes). because I need to multiply with some value after this logic. Can anyone helpme on this.

//utc_start and utc_end time are date/time field
var start_time = new GlideDuration(current.utc_start_time);
var end_time = new GlideDuration(current.utc_end_time);
var currentTime = new GlideDateTime();
var current_time = new GlideDuration(currentTime);

var myDuration;

if (current.u_utc_end_time != "") {
myDuration = end_time.subtract(start_time);
}
} else {
myDuration = current_time.subtract(start_time);
}

var minutes = myDuration.getNumericValue();

var res1 = minutes * current.count;

1 ACCEPTED SOLUTION

OlaN
Giga Sage
Giga Sage

Hi,

Here is an example to get the difference in minutes on two DateTime objects.

var startDate = new GlideDateTime(current.getValue('your_start_time_field'));
var endDate = new GlideDateTime(current.getValue('your_end_time_field'));

var differenceMS = endDate.getNumericValue() - startDate.getNumericValue();
var diffMinutes = differenceMS / (60 * 1000);

gs.info('diff Min: ' + diffMinutes);

View solution in original post

5 REPLIES 5

thank you very much