Incident Escalation Portal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-10-2025 05:17 AM
I'm using the following server script to hide the Escalate button.
My requirement is:
When an incident is created, the Escalate button should become visible the next day.
If the user clicks the Escalate button, it should again become available the next day for another escalation.
The logic works as expected when I compare with minutes and seconds — the button appears correctly.
However, when I try to compare using only days (without considering time), the button doesn’t appear at all.
Server Script:
(function() {
var incidentGr = new GlideRecord('incident');
var incidentSysId = options.sys_id;
if (!incidentSysId && $sp.getParameter('table') == 'incident')
incidentSysId = $sp.getParameter('sys_id');
if (!incidentSysId && $sp.getParameter('table') == 'universal_request') {
var urGr = new GlideRecord('universal_request');
urGr.get($sp.getParameter('sys_id'));
incidentSysId = urGr.primary_task + "";
}
var datetime = new GlideDateTime().getDisplayValue();
/* Actions - Start */
if (input && input.action == 'resolveIncidentComments' && !gs.nil(input.resolveComments) && incidentGr.get(incidentSysId)) {
incidentGr.incident_state = global.IncidentState.RESOLVED;
incidentGr.state = global.IncidentState.RESOLVED;
incidentGr.resolved_by = gs.getUserID();
incidentGr.resolved_at = datetime;
incidentGr.close_notes = input.resolveComments;
incidentGr.close_code = 'Closed/Resolved by Caller';
incidentGr.comments = gs.getMessage("Resolve Comments") + ": " + input.resolveComments;
data.isIncidentResolved = incidentGr.update();
}
if (input && input.action == 'escalateIncidentComments' && incidentGr.get(incidentSysId)) {
if (incidentGr.u_escalated == false) {
incidentGr.u_escalated = true;
incidentGr.u_escalated_count = 0;
incidentGr.u_escalated_created_on = datetime;
}
incidentGr.u_escalation_categor = input.escalation_reason_category;
incidentGr.u_escalated_count = incidentGr.u_escalated_count + 1;
incidentGr.u_escalation_moditification_on = datetime;
if (!gs.nil(input.escalationComments)) {
incidentGr.comments = "[code]<b>" + gs.getMessage("Escalation Journal Title") + "</b>[/code]: " + input.escalationComments;
}
data.isIncidentEscalated = incidentGr.update();
}
if (input && input.action == 'reopenIncident' && incidentGr.get(incidentSysId)) {
incidentGr.incident_state = global.IncidentState.IN_PROGRESS;
incidentGr.state = global.IncidentState.IN_PROGRESS;
data.isIncidentReopened = incidentGr.update();
gs.addInfoMessage(gs.getMessage("Request reopened"));
}
/* Actions - End */
/* Load incident data */
if (incidentGr.get(incidentSysId)) {
var incidentUtils = new global.IncidentUtils();
data.canResolve = incidentUtils.canResolveIncident(incidentGr);
// Custom logic for escalate button visibility
data.canEscalate = false; // Default to false
var now = new GlideDateTime();
var createdOn = new GlideDateTime(incidentGr.sys_created_on);
var timeSinceCreation = now.getNumericValue() - createdOn.getNumericValue();
var oneDayInMs = 24 * 60 * 60 * 1000; // 24 hours in milliseconds
// Check if 24 hours have passed since incident creation
if (timeSinceCreation >= oneDayInMs) {
// If never escalated, allow escalation
if (!incidentGr.u_escalated || gs.nil(incidentGr.u_escalation_moditification_on)) {
data.canEscalate = incidentUtils.canEscalateIncident(incidentGr);
} else {
// Check if 24 hours have passed since last escalation
var lastEscalation = new GlideDateTime(incidentGr.u_escalation_moditification_on);
var timeSinceLastEscalation = now.getNumericValue() - lastEscalation.getNumericValue();
if (timeSinceLastEscalation >= oneDayInMs) {
data.canEscalate = incidentUtils.canEscalateIncident(incidentGr);
}
}
}
data.canReopen = incidentUtils.canReopenIncident(incidentGr);
data.showActions = data.canResolve || data.canEscalate || data.canReopen;
}
data.i18n = {};
})();