Extension date in policy exception table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-26-2025 02:36 AM
I need to create a new function within the existing child Script Include and invoke it in the 'else' block of my Business Rule. The goal is to enable extending the extension date in the Policy Exception form beyond one year from the 'Valid To' field. Currently, this is functioning as expected, but I've temporarily commented out the 'else' block in the Business Rule. Instead of commenting it out, I'd like to implement a solution that incorporates the new function while retaining the original 'else' logic. Looking for suggestions on how best to structure this.
Below are my existing script include and business rule.
Script Include
Business rule:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-26-2025 02:55 AM
didn't get where are you stuck?
would be better to share scripts rather than image as it becomes difficult to read and interpret.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-26-2025 03:01 AM
var PolicyException = Class.create();
PolicyException.prototype = Object.extendsObject(PolicyExceptionBase, {
/** Override base class functions here. **/
isExceptionDurationValid: function(policy, controlObjective, validFrom, validTo) {
return this._isExceptionDurationValid(policy, controlObjective, validFrom, validTo);
},
_isExceptionDurationValid: function(policy, controlObjective, validFrom, validTo) {
var result = {};
var maxExceptionDuration = gs.getProperty("sn_compliance.u_maximum_exception_review_duration");
var maxExceptionDurationForPolicy;
if (policy) {
maxExceptionDurationForPolicy = this.getMaxExceptionDurationForPolicy(policy);
if (maxExceptionDurationForPolicy) {
maxExceptionDuration = maxExceptionDurationForPolicy;
}
} else if (controlObjective) {
maxExceptionDurationForPolicy = this.getMaxExceptionDurationForCtrlObj(controlObjective);
if (maxExceptionDurationForPolicy) {
maxExceptionDuration = maxExceptionDurationForPolicy;
}
}
if (maxExceptionDuration) {
var validFromMs = new GlideDateTime(validFrom).getNumericValue();
var validToGdtMs = new GlideDateTime(validTo).getNumericValue();
var exceptionDurationInDays = Math.ceil((validToGdtMs - validFromMs) / (24 * 3600 * 1000));
if (exceptionDurationInDays > maxExceptionDuration) {
result.errorMessage = gs.getMessage(
'The duration of this policy exception cannot be more than {0} days from "Valid from" date.',
maxExceptionDuration
);
}
}
return result;
},
type: 'PolicyException'
});
Business rule:
(function executeRule(current, previous /*null when async*/ ) {
var result = {};
if (current.requested_valid_to != previous.requested_valid_to) {
result = new PolicyException().isExceptionDurationValid(
current.policy,
current.policy_statement,
current.valid_to,
current.requested_valid_to
);
if (result.errorMessage) {
gs.addErrorMessage(result.errorMessage);
current.setAbortAction(true);
}
var validTo = new GlideDateTime(current.valid_to);
var extensionDate = new GlideDateTime(current.requested_valid_to);
if (validTo.getNumericValue() >= extensionDate.getNumericValue()) {
gs.addErrorMessage(gs.getMessage('Extension date must be after Valid to'));
current.setAbortAction(true);
}
}
/* else {
result = new PolicyException().isExceptionDurationValid(
current.policy,
current.policy_statement,
current.valid_from,
current.valid_to
);
if (result.errorMessage) {
gs.addErrorMessage(result.errorMessage);
current.setAbortAction(true);
}
} */
})(current, previous);