Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2023 03:14 AM
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);
Solved! Go to Solution.
1 ACCEPTED SOLUTION

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2023 01:10 AM
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.
10 REPLIES 10
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2023 11:13 AM
I have it set to Before Insert and Update. Should it be Insert only?