Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Prevent Creation of incidents with the same short description

Community Alums
Not applicable

Prevent Creation of incidents with the same short description

1 ACCEPTED SOLUTION

sreeshsurendran
Tera Guru

Hi @Community Alums , you can use before Business Rule with insert and update checked where condition will be 'short description changes'

 

Here is the script : 

 

(function executeRule(current, previous /*null when async*/ ) {

    // Add your code here
    var shortDescription = current.short_description;
    var gr = new GlideRecord('incident');
    gr.addQuery('short_description', shortDescription);
    gr.query();
    if (gr.hasNext()) {
        gs.addErrorMessage('Short Description already exists');
        current.setAbortAction(true);
    }
})(current, previous);

 

Note : you can replace hasNext() with next() if you want to show the Incident Number on the error message.

 

Mark this as solution if it's working 🙂

View solution in original post

6 REPLIES 6

sreeshsurendran
Tera Guru

Hi @Community Alums , you can use before Business Rule with insert and update checked where condition will be 'short description changes'

 

Here is the script : 

 

(function executeRule(current, previous /*null when async*/ ) {

    // Add your code here
    var shortDescription = current.short_description;
    var gr = new GlideRecord('incident');
    gr.addQuery('short_description', shortDescription);
    gr.query();
    if (gr.hasNext()) {
        gs.addErrorMessage('Short Description already exists');
        current.setAbortAction(true);
    }
})(current, previous);

 

Note : you can replace hasNext() with next() if you want to show the Incident Number on the error message.

 

Mark this as solution if it's working 🙂

Community Alums
Not applicable

Hi @sreeshsurendran  -  thanks it's working as expected

Rahul Kumar17
Tera Guru

Hi,

Create before business rule with condition
Use a condition like current.short_description.changes() && current.short_description.getJournalEntry(1).newValue === current.short_description.getJournalEntry(2).newValue.

also write script

 

current.setAbortAction(true);
gs.addErrorMessage("Another incident with the same short description already exists.");

 

 

Thanks,

Rahul Kumar

If my response helped please mark it correct and close the thread.

Thanks,
Rahul Kumar

Barry Kant
ServiceNow Employee
ServiceNow Employee

To be sure:
is this a real requirement?