Business Rule for preventing duplicate software entitlements

Jiajie Li
Tera Contributor

Hello experts, 

 

I am trying to create a business rule to prevent duplicate software entitlements when a request is submitted. Below is the code I have but when a request is submitted it causes an abort when checking for duplicates. Thanks for any help!

 

(function executeRule(current, previous /*null when async*/) {
    // Check for existing entitlement with the same software and licensee
    var gr = new GlideRecord('alm_entitlement'); //create a new GlideRecord to query "alm_entitlement" table
    gr.addQuery('software', current.software); //query the software field
    gr.addQuery('licensed_by', current.licensed_by); //query the licensed_by field
    gr.query();

    if (gr.next()) { //checks if there is at least one record in the result set of the GlideRecord query. 
    gs.log("test5");
    //If there is a matching record, the next() returns true, and the code inside the if statement is run.
        gs.addErrorMessage('Duplicate software entitlement found.'); //display error message
        current.setAbortAction(true); //abort process
    }
})(current, previous);
 
Below is the error:
Flow Designer: Operation(Software Request.If$9.1b44563b97c431502a7733471153afeb.624b63b5979c39502a7733471153af3e.f9e09916c31332002841b63b12d3aeaa) failed with error: com.snc.process_flow.exception.OpException: Error occured while inserting record: Operation against file 'alm_entitlement_user' was aborted by Business Rule 'Ensure no duplicate entitlements^3eb21ced97f03d102a7733471153af6b'. Business Rule Stack:Ensure no duplicate entitlements
1 REPLY 1

SwarnadeepNandy
Mega Sage

Hello @Jiajie Li,

 

I would recommend using IRE.

Define Identification rules to reject duplicate creation.

In this way you avoid writing scripts wherever possible.

 

Kind Regards,

Swarnadeep Nandy