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.

Duration filed returning in Date format

Community Alums
Not applicable

Hi,

Requirement is to sum all the duraion field values and get the average.. for that I am calculating duration between two date fields using dateDiff function and storing result in a duration type field, But I am receiving duration in date format i.e; 1970-01-08 01:25:10 .Display value is in duration format ( 7: 0:01:56) but when I try to print it its getting displayed in date(1970-01-08 01:25:10) format. Please help me to solve the issue.Thank you

var app = new GlideRecord('sysapproval_approver');
app.addQuery('source_table','change_request');
app.addQuery('state','requested');
app.query();
while(app.next()){
e = gs.dateDiff(app.sys_created_on, app.due_date);
app.u_durationduration = e;
    app.update();

}

 

1 REPLY 1

Muhammad Khan
Mega Sage

Hi,

Try below script.

var app = new GlideRecord('sysapproval_approver');
app.addQuery('source_table','change_request');
app.addQuery('state','requested');
app.query();
while(app.next()){
    e = gs.dateDiff(app.sys_created_on.getDisplayValue(), app.due_date.getDisplayValue());
    app.u_durationduration.setDisplayValue(e);
    app.update();
    // gs.print(app.u_durationduration.getDisplayValue());
}