u_updateTaskAging(); function u_updateTaskAging() { var elapsedTime = 0; var aging=""; var gr = new GlideRecord('incident'); gr.addEncodedQuery('stateNOT IN7,8'); gr.orderByDesc("sys_created_on"); gr.query(); while (gr.next()) { var gr1 = new GlideRecord("metric_instance"); gr1.addEncodedQuery("duration!=NULL^value=On Hold^definition=35f2b283c0a808ae000b7132cd0a4f55^id=" + gr.sys_id); gr1.query(); if (gr1.next()) { aging=""; elapsedTime = (gs.dateDiff(gr1.start, gr1.end, true)) / 60 / 60 / 24; if (elapsedTime <= 6) { aging = '0-6days'; } if ((elapsedTime > 6) && (elapsedTime <= 30)) { aging = '7-30days'; } if (elapsedTime > 30) { aging = '>30days'; } gr.setWorkflow(false); // Skip any Business Rules gr.autoSysFields(false); // Do not update system fields gr.u_aging_onhold = aging; gr.update(); } } }
How to capture onHold time in incident form ServiceNow
Working Code Asked question August 21, 2024