Unable to display error message with gs.addErrorMessage() or gs.addErrorMessage(gs.getMessage())

Jiajie Li
Tera Contributor

Hello experts,

 

I am trying to prevent duplicate software entitlements. If a duplicate is found, I want the request to abort and an error to show up. However, the error is not showing up. I tried both below:

gs.addErrorMessage(gs.getMessage('Duplicate software entitlement found'));//display error message
gs.addErrorMessage("Duplicate software entitlement found");//display error message

 

Below is the full business rule script:

 

(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('assigned_to', current.assigned_to); //query the assigned_to field
    gr.addQuery('licensed_by', current.licensed_by); //query the licensed_by field
    gr.query();

    if (gr.hasNext()) { //checks if there is at least one record in the result set of the GlideRecord query. 
    //If there is a matching record, the hasNext() returns true, and the code inside the if statement is run.
        gs.addErrorMessage(gs.getMessage('Duplicate software entitlement found'));//display error message
        gs.addErrorMessage("Duplicate software entitlement found");//display error message
        current.setAbortAction(true); //abort process
    }
})(current, previous);
1 ACCEPTED SOLUTION

I would suggest to update the RITM with additional comments to update the user.


Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.

View solution in original post

10 REPLIES 10

I have it set to Before Insert and Update. Should it be Insert only? 

 

Capture.PNG