- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi Team,
I’m working on a requirement to enforce a 48-hour closure hold on Change Requests and would appreciate guidance on the best-practice approach in ServiceNow.
Requirement details:
Users must not be able to move a Change to the “Closed” state until 48 hours have elapsed after the Planned End Date/Time.
The rule should apply to the following Change types:
Normal
Standard
Emergency
Until the 48-hour window is completed, the system should block the update and display a user-friendly error message, such as:
“You cannot close this Change until 48 hours after the Planned End Date/Time.”
Thanks in Advance
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @Kishore47 ,
Use a Business Rule (before update) on the change_request table.It runs server-side, so it’s enforced regardless of UI (Classic, Service Portal, API).Can block the update before it happens.Can show a friendly error message.
Condition:state changes to (Closed) AND type IN Normal, Standard, Emergency
(function executeRule(current, previous /*null when async*/) {
// Only for Normal, Standard, Emergency changes
var changeTypes = ['Normal', 'Standard', 'Emergency'];
if (changeTypes.indexOf(current.type.toString()) == -1)
return;
// Only when user is trying to move to Closed (state = 7)
if (current.state != 7)
return;
// Calculate 48 hours after Planned End Date/Time
var plannedEnd = current.planned_end_date; // Make sure this is the correct field
if (!plannedEnd) {
gs.addErrorMessage("Planned End Date/Time is missing. Cannot close the Change.");
current.setAbortAction(true);
return;
}
var now = new GlideDateTime();
var plannedEndDateTime = new GlideDateTime(plannedEnd);
plannedEndDateTime.addSeconds(48 * 60 * 60); // add 48 hours
if (now < plannedEndDateTime) {
gs.addErrorMessage("You cannot close this Change until 48 hours after the Planned End Date/Time.");
current.setAbortAction(true); // blocks the update
}
})(current, previous);check your backend values and repalce it
If you found my solution helpful, please mark it as Helpful or Accepted Solution...!
thanks,
tejas
Email: adhalraotejas1018@gmail.com
LinkedIn: https://www.linkedin.com/in/tejas1018
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hello @Kishore47
I think my response also proved beneficial to you, you can accept multiple solutions 🙂
Warm Regards
Sumit
Technical Consultant
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @Kishore47 ,
Use a Business Rule (before update) on the change_request table.It runs server-side, so it’s enforced regardless of UI (Classic, Service Portal, API).Can block the update before it happens.Can show a friendly error message.
Condition:state changes to (Closed) AND type IN Normal, Standard, Emergency
(function executeRule(current, previous /*null when async*/) {
// Only for Normal, Standard, Emergency changes
var changeTypes = ['Normal', 'Standard', 'Emergency'];
if (changeTypes.indexOf(current.type.toString()) == -1)
return;
// Only when user is trying to move to Closed (state = 7)
if (current.state != 7)
return;
// Calculate 48 hours after Planned End Date/Time
var plannedEnd = current.planned_end_date; // Make sure this is the correct field
if (!plannedEnd) {
gs.addErrorMessage("Planned End Date/Time is missing. Cannot close the Change.");
current.setAbortAction(true);
return;
}
var now = new GlideDateTime();
var plannedEndDateTime = new GlideDateTime(plannedEnd);
plannedEndDateTime.addSeconds(48 * 60 * 60); // add 48 hours
if (now < plannedEndDateTime) {
gs.addErrorMessage("You cannot close this Change until 48 hours after the Planned End Date/Time.");
current.setAbortAction(true); // blocks the update
}
})(current, previous);check your backend values and repalce it
If you found my solution helpful, please mark it as Helpful or Accepted Solution...!
thanks,
tejas
Email: adhalraotejas1018@gmail.com
LinkedIn: https://www.linkedin.com/in/tejas1018
