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 01:33 PM
SM aaS is still not being enabled when I create an Entitlement using one of the Model Numbers in the BR.
When creating the Entitlement:
Model Number ('model_number') = 023-220021-001
Status ('u_service_line_status') = ACTIVE
Start Date: 08/17/23
End Date: 08/17/24
Active ('active') = true
(function executeRule(current, previous /*null when async*/) {
// Create Variables
var hasActiveEntitlements = false; // We will assume that all Entitlement are Active by default
var account = current.account; // Get the sys_id of the related account
var model_numbers = ['list','model','numbers','here'];
// Query the entitlement table for any inactive record related to the account
var gr = new GlideRecord('service_entitlement');
gr.addQuery('account',account);
gr.addQuery('model.model_number','IN',model_numbers);
gr.addQuery('active',true);
gr.query();
if (gr.next()) {
if (model_numbers.includes(gr.model.model_number)) {
hasActiveEntitlements = true;
}
}
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 (hasActiveEntitlements) {
gr1.u_sm_aas = 'true';
} else {
gr1.u_sm_aas = 'false';
}
gr1.setWorkflow(false);
gr1.update(); // Update the record
}
})(current,previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā08-17-2023 01:41 PM
I noticed in the BR Filter Conditions, Field name is Product Model.Model number. Does that mean anything in regards to the script/code? Instead of model.model_number?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā08-17-2023 02:40 PM
That could definitely be the cause, I am not sure what the field names is for that particular field. What you are seeing in the condition is the field label, so you will have to find out the actual field name for that field. If you are an admin, you can right click the 'Product Model' label on the form and it will show you the field name.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā08-17-2023 03:00 PM
It's 'product'.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā08-17-2023 03:05 PM
Here's the Dictionary Entries for Product Model and Model Number fields.