Need to display pop up message while nonprod environment change request should not allow Prod affec

Satyanarayana r
Tera Contributor

Need to display error message while nonproduction environment change request should not allow Production affected CI's.

able to restrict the not to add Pro affected ci's to Non prod change requests but not pop up message.

 

Please advice.

2 REPLIES 2

Thota Naga Jyo1
Tera Contributor

Tri this Business rule: 

  1. Set the Table to Change Request.
  2. Set the When to run to Before and Insert and Update.

(function executeRule(current, previous /*null when async*/) {
var nonProdCIs = []; // Array to hold non-production CIs
var prodCIs = []; // Array to hold production CIs

// Loop through all the CIs in the change request
var ciGR = new GlideRecord('cmdb_ci');
ciGR.addQuery('sys_id', 'IN', current.cmdb_ci.toString());
ciGR.query();
while (ciGR.next()) {
// Determine if the CI is Production or Non-Production
if (ciGR.u_environment == 'Production') {
prodCIs.push(ciGR.name.toString());
} else {
nonProdCIs.push(ciGR.name.toString());
}
}

// Check if there are any Production CIs in the Non-Production environment
if (prodCIs.length > 0 && current.u_environment == 'Non-Production') {
// Display error message and prevent save
gs.addErrorMessage('Production CIs cannot be included in Non-Production change requests. Production CIs: ' + prodCIs.join(', '));
current.setAbortAction(true);
}
})(current, previous);

 

 

 

Thank you,

If my answer has helped with your question, please mark my answer as accepted solution and mark as helpful

Hi Naga,

 My requirement is here,  throw an error message when you are trying to add Production affected CI's to the Non production change request.

 

thanks,