Calculate duration*numeric value and display in minutes

Vijayr119
Tera Contributor

I'm trying to calculate the impacted users based on below format and getting wrong result

Impacted Minutes = Duration * Impacted Users

Impacted Minutes(String Type) = Duration (Duration Type) * Impacted Users (STring Type)

And the result should be displayed in the minutes

 

find_real_file.png

(function executeRule(current, previous /*null when async*/) {
var dur = current.duration.getGlideObject().getNumericValue();
dur = dur/1000;
var total = parseInt(current.u_users_impacted)*dur;
// var total = current.u_users_impacted*dur;
var total1=total/60; //convert to mins
current.u_customer_impacted_minutes = total1;
})(current, previous);

 

 

 

1 ACCEPTED SOLUTION

Update the code like below:

 

(function executeRule(current, previous /*null when async*/) {
var dur = current.duration.getGlideObject().getNumericValue();
dur = dur/1000;
dur = dur/60; // Converting the seconds in minutes
var total = parseInt(current.u_users_impacted)*dur;
// var total = current.u_users_impacted*dur;
//var total1=total/60; //convert to mins
current.u_customer_impacted_minutes = Math.floor(total);
})(current, previous);

 

This will set 34

View solution in original post

4 REPLIES 4

Ankur Swami
Tera Guru

hi,

 

You were converting the whole calculation in the minutes you must convert the seconds to minutes and then you should apply you calculation.

I have modified the script as given below.

 

(function executeRule(current, previous /*null when async*/) {
var dur = current.duration.getGlideObject().getNumericValue();
dur = dur/1000;
dur = dur/60; // Converting the seconds in minutes
var total = parseInt(current.u_users_impacted)*dur;
// var total = current.u_users_impacted*dur;
//var total1=total/60; //convert to mins
current.u_customer_impacted_minutes = total;
})(current, previous);

 

Thanks,

Ankur

Its still giving the wrong result

find_real_file.png

 

Result should be: 34 not 34.0666

Update the code like below:

 

(function executeRule(current, previous /*null when async*/) {
var dur = current.duration.getGlideObject().getNumericValue();
dur = dur/1000;
dur = dur/60; // Converting the seconds in minutes
var total = parseInt(current.u_users_impacted)*dur;
// var total = current.u_users_impacted*dur;
//var total1=total/60; //convert to mins
current.u_customer_impacted_minutes = Math.floor(total);
})(current, previous);

 

This will set 34

Checked with  75*17 = 1277 (This result)

But this should be 1275

 

Why its happening?