difference of two field need to store in another field in incident form

Mansi roy
Tera Contributor

Hello All,

 

I have the below requirement.

 

I have three types field.

 

Mansiroy_0-1724833712674.png

 

Here the total duration is not giving the correct result. I have written the below before business rule script.

 

(function executeRule(current, previous /*null when async*/) {
var startTime = current.u_onhold_duration.dateNumericValue();
var endTime = current.u_onhold_end_time.dateNumericValue();
current.u_total_duration.setDateNumericValue(endTime-startTime);
})(current, previous);
 
but it is not giving the correct result.
 
Can anyone please help me on this.
2 REPLIES 2

Mark Manders
Mega Patron

Can you try this? Duration fields are a bit trickier than date/time fields. 

(function executeRule(current, previous /*null when async*/) {
    var startTime = current.u_onhold_duration.getValue(); 
    var endTime = current.u_onhold_end_time.getValue();
    
    var totalDurationInSeconds = parseInt(endTime) - parseInt(startTime);

    // Convert the result back to a duration format or store it as needed
    current.u_total_duration.setValue(totalDurationInSeconds.toString()); 
})(current, previous);

 


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

@Mark Manders It is not giving any result.Not getting calculated.