Restrict the raising of changes within a change window
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2024 06:49 AM - edited 07-18-2024 07:09 AM
Hi
ive set up a BR to restrict the amount of Normal changes that can have the same start_time
Before, update, change_request
- (function executeRule(current, previous /*null when async*/) {
- // Add your code here
- // Create an aggregate object
- var pt = new GlideAggregate('change_request');
- // Add aggregate
- pt.addAggregate('COUNT');
- // Execute query
- pt.addQuery('change_request', 'start_date');
- pt.addQuery('active', true);
- pt.addQuery('start_date', current.getValue('start_date'));
- pt.query();
- // Process returned records
- if (pt.next()) {
- count = pt.getAggregate('COUNT');
- if (count > 4) {
- // Create a message to display the count
- gs.addErrorMessage('You cannot save this Change. ' + pt.getAggregate('COUNT') + ' Changes are already planned for this start time.');
- current.setAbortAction(true);
- }
- }
- })(current, previous);
but i want to take it one step further and compare the planned start and planned end window and restrict the raising of a change if the count hits within that change window
any help would be much apprieciated
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2024 06:52 AM
Hi @Ross Walker
Practically it is not a good option, in this case, you are blocking all kinds of changes including emergencies, Instead if this, if a change in conflict like the above, you'd better add an extra layer of approval instead of restricting it all the way.
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2024 07:01 AM
this is only for normal changes
it doesnt stop any other type
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2024 07:53 AM
Hi @Ross Walker ,
You can use out of box "Check Conflict" functionality and use it in your UI Action using client script to show alert before submitting change.
//Code that runs without 'onclick'
//Ensure call to server-side function with no browser errors
if (typeof window == 'undefined')
checkConflicts();
function checkConflicts() {
suppressMaintenanceScheduleMessages = true;
var conflictDetector = new ChangeCheckConflicts(current);
var conflictResults = conflictDetector.check();
current.conflict_status = 'No Conflict';
var msg;
if (conflictResults < 0)
msg = gs.getMessage('Configuration Item needed for conflict analysis');
else if (conflictResults == 0)
msg = gs.getMessage('There are <FONT COLOR="green">NO CONFLICTS</FONT>');
else {
msg = gs.getMessage('There <FONT COLOR="tomato">ARE CONFLICTS</FONT> - See "Conflicts" related list');
current.conflict_status = 'Conflict';
}
Plz mark my solution as Accept, If you find it helpful.
Thanks & Regards,
Sumanth meda