Business Rule not working as desired
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā08-17-2023 11:47 AM
We have a Business Rule that will mark a true/false box (SM aaS/u_sm_aas) on our Account form true, if the Account has an Active Entitlement with a certain Product Model Number (see attached screenshot/s). It is marking the box true when an Entitlement is created with one of the Product Model Numbers, but if it expires and the Entitlement changes to false, the SM aaS box remains true. I've tested this with just one Entitlement on the Account. So, it didn't need to check for other active/deactivated Entitlements with one of these Model Numbers.
So, the Business Rule needs to check all the Entitlements on the Account to see if any of the Part Numbers are listed. If it does, and any are Active, the SM aaS box should be true. If it checks to see if any Entitlements have any of those Model Numbers and all are not Active, then it needs to make the SM aaS box false. Can this be configured in the script? For example, whenever any Entitlement is added/inserted or updated, it checks for these conditions? Or, do you think this is better configured as a Scheduled Job/script? To run a few times per day? If script updates are required, can you provide sample code?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā08-17-2023 11:59 AM - edited ā08-17-2023 12:09 PM
What table are you triggering the business rule on?
Also what would be the ideal trigger (ie. Update Record, Insert Record, etc.)
You could write a client script (which would have some more complexity) but then it would trigger whenever you load the record, however if you want the field to change without having to open the record, you probably want to configure your business rule to trigger on insert/update for the alm_license table (Software Entitlement). This way when the Entitlement expires it updates the record and triggers the BR.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā08-17-2023 12:22 PM
The Entitlement table (service_entitlement).
The BR is configured for insert and update. At least those boxes are checked on the BR (first screenshot above). The thing is, the Account can possibly have 5 Entitlements with each having a different Model Number that's mentioned in the BR. One of these Entitlements can expire (Active = false), but the other Entitlements still match the conditions, so the SM aaS box should still be true. So, the SM aaS box will stay true until there are no more Active Entitlements with one of the Model Numbers mentioned in the BR.
I figured when the Entitlement expired and Active changed to false (an update), the BR would run. But, when I tested against an Account that only had one Entitlement that had one of the Model Numbers in the BR and I deactivated it, the SM aaS box didn't change to false like it should of.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā08-17-2023 12:34 PM - edited ā08-17-2023 12:35 PM
Well right away, when the entitlement expires the rule won't trigger due to the filter you configured (Active = True). After this change, your script will only update the account records u_sm_aas field to true. If you want it to change it to false as well, you will have to add the necessary logic for it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā08-17-2023 12:28 PM - edited ā08-17-2023 12:29 PM
To start, I am assuming you have the table for your business rules set as the Entitlement table, if so I would change the Filter Conditions in your business rule to remove the Active is true filter, otherwise when an entitlement expires, it will not be picked up by the business rule because it is no longer active. Instead lets incorporate this logic into our code.
The code would like something like:
(function executeRule(current, previous /*null when async*/) {
// Create Variables
var allEntitlementsActive = true; // We will assume that all Entitlement are Active by default
var account = current.account; // Get the sys_id of the related account
// Query the entitlement table for any inactive record related to the account
var gr = new GlideRecord('entitlement_table_name_here');
gr.addQuery('account',account);
gr.addQuery('active',false);
gr.query();
if (gr.next()) {
allEntitlementsActive = false;
}
// Get the related account
var gr1 = new GlideRecord('customer_account');
gr1.get(account);
gr1.query();
if (gr1.next()) {
// If no results were found earlier, this will be true otherwise, it will be false.
if (allEntitlementsActive) {
gr1.u_sm_aas = 'true';
} else {
gr.u_sm_aas = 'false';
}
gr1.setWorkflow(false);
gr1.update(); // Update the record
}
})(current,previous)
NOTE: This code is untested, so results may vary.
I would try this and see if it does what you are looking for.