Restrict the raising of changes within a change window

Ross Walker
Tera Contributor

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 
3 REPLIES 3

Dr Atul - LNG
Tera Patron

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.

this is only for normal changes
it doesnt stop any other type

Sumanth16
Mega Patron

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