Getting the wrong Business Duration value on RITM table

raj99918
Tera Contributor

Hi 

Getting the wrong Business Duration value(Mostly getting 0 value or Garbage value) on RITM table even I used the code same as incident mark_closed BR however on incident table have the same wrong data below is the code:

 

(function executeRule(current, previous /*null when async*/ ) {
        var opened = current.opened_at.getDisplayValue();
        var closed = current.closed_at.getDisplayValue();

        if (current.business_duration.nil())
            current.business_duration = gs.calDateDiff(opened, closed, false); // Business Duration

        if (current.calendar_duration.nil())
            current.calendar_duration = gs.dateDiff(opened, closed, false); // Duration
}
)(current, previous);

 

4 REPLIES 4

Abhay Kumar1
Giga Sage

@raj99918 Try to use getValue instead of getdisplayvalue, this should work please find below refined code:

(function executeRule(current, previous /*null when async*/ ) {

    var opened = current.opened_at.getValue();

    var closed = current.closed_at.getValue();

 

    if (opened && closed) { // Ensure both fields have values

        if (current.business_duration.nil())

            current.business_duration = gs.calDateDiff(opened, closed, false); // Business Duration

 

        if (current.calendar_duration.nil())

            current.calendar_duration = gs.dateDiff(opened, closed, false); // Duration

    }

})(current, previous);

Hi @Abhay Kumar1 Thanks for the reply but just want to ask onething even OOB BR have the same getdisplayvalue May I know the reason for this ?

 

 

@raj99918  getDisplayValue() retrieves the date in the user's display format, which may differ from the system format. Using getValue() may avoid formatting issues if dates are being interpreted incorrectly. This is the reason I had suggested. 

Ankur Bawiskar
Tera Patron
Tera Patron

@raj99918 

this is OOB BR.

So are you saying it's not working as expected?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader