business rule

sola27
Tera Contributor

Hello, I am trying to make a BR to prevent P1 incident creation if the CI is not something specific.If the user selects another CI it should throw an error "Please select the CI as XX to create a P1 record". This is what I got so far:

 

(function executeRule(current, previous /*null when async*/ ) {
 
var inc = new GlideRecord('incident');
inc.addEncodedQuery('cmdb_ci!=d0e8761137201000deeabfc8bcbe5da7^priority=1');
inc.query();
if (inc.next()) {
        current.setAbortAction(true);
gs.addErrorMessage('Please select the CI as *DENNIS-IBM to create a P1 record');
    }
 
})(current, previous);

 

But is not saving the ticket even when the CI is set to the specified CI. Can someone assists with this? Thank you in advance.

1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

You shouldn't need a GlideRecord.  This sounds like you want a before Insert Business Rule on the incident table.  Your script would look more like this:

(function executeRule(current, previous /*null when async*/ ) {
    if (current.cmdb_ci != 'd0e8761137201000deeabfc8bcbe5da7' && current.priority == 1){
        current.setAbortAction(true);
        gs.addErrorMessage('Please select the CI as *DENNIS-IBM to create a P1 record');
    }
 })(current, previous);

View solution in original post

1 REPLY 1

Brad Bowman
Kilo Patron
Kilo Patron

You shouldn't need a GlideRecord.  This sounds like you want a before Insert Business Rule on the incident table.  Your script would look more like this:

(function executeRule(current, previous /*null when async*/ ) {
    if (current.cmdb_ci != 'd0e8761137201000deeabfc8bcbe5da7' && current.priority == 1){
        current.setAbortAction(true);
        gs.addErrorMessage('Please select the CI as *DENNIS-IBM to create a P1 record');
    }
 })(current, previous);