Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

glide duration field not populating

kushagrasingh
Tera Contributor

Hi everyone, I want to populate a new created field named 'on hold duration' in the incident form, when the state of incident is changing to on hold. I want the new field to hold the duration of the incident being in on hold state.

Here is the code that I wrote for the 'after' business rule when state is 'on hold':

var onHoldMetric = new GlideRecord('metric_instance');

    var present = new GlideDateTime();

    gs.info(onHoldMetric.id.getDisplayValue + " " + present);

    onHoldMetric.addEncodedQuery('definition=35f2b283c0a808ae000b7132cd0a4f55^value=On Hold^end=NULL')

    onHoldMetric.query();

    while(onHoldMetric.next()) {

        if(onHoldMetric.id == current.sys_id) {

            var startOnHold = new GlideDateTime(onHoldMetric.start);

            current.u_on_hold_duration = GlideDateTime.subtract(startOnHold, present);

        }

  }

this is not working.

1 REPLY 1

Sujatha V M
Kilo Patron
Kilo Patron

@kushagrasingh You can create as below using GlideFunction() using function field and define the fields for calculation. 

 

SujathaVM_0-1712640520713.png

 

Please mark this as helpful and accept it as a solution if this resolves your query.

Thanks,

Sujatha V.M.

 

Please mark this as helpful and accept it as a solution if this resolves your query.
Sujatha V.M.