Compare a variable to a metric of greater than less than for approval
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2024 07:49 PM
My description isn't great, but it is hard to explain. I have a matrix that is filling a variable field based on data lookup definitions. I need to compare this field (tier level) against a criteria.
Example:
The field is populated by lookup definitions to be T1-T4
Another custom table contains risk level (1-6)
If the lookup definition is T4, risk levels that are eligible can be 1-6. If the lookup definition is T2, risk levels that are eligible are 1,2,5.
Any advice is appreciated. I feel like it could be a greater than or less than comparison, but because the numbers skip I am just not sure.
Thanks,
Erin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2024 09:14 PM
Hi @erin-marie
In this scenario, you’ll likely be implementing business logic within ServiceNow to manage the relationship between a tier level (T1-T4) as defined by lookup definitions and a risk level (1-6) stored possibly in a custom table. Creating this relationship and implementing the logic can be approached in several ways within ServiceNow. Here’s a method you could consider:
### Step 1: Define Your Data Model
First, ensure you clearly define how your data is structured. For illustration:
- Tier Levels: Let’s suppose these are stored or determined via a Lookup Definition that assigns a tier level (T1 - T4) to a specific item or scenario.
- Risk Levels: These are stored in a custom table (e.g., u_risk_levels) and can range from 1-6.
### Step 2: Create a Mapping Table
A practical way to manage the eligible risk levels for each tier is to have a mapping table in ServiceNow. This table can explicitly define which risk levels are valid for each tier.
1. Table Structure: Create a new table, for example, u_tier_risk_mapping, with these fields:
- Tier Level (u_tier_level😞 A choice field that defines the tier (T1 - T4).
- Eligible Risk Level (u_eligible_risk_level😞 A reference field to your risk level table (u_risk_levels).
2. Populate Data: Enter the mapping data according to your criteria (for T4, all risks 1-6 are eligible; for T2, risks 1,2,5 are eligible, and so on).
### Step 3: Business Logic to Utilize the Mapping
When you need to assess if a specific risk level is eligible for your item/scenario based on its tier, you will query this mapping table.
For example, if you have an item with a tier T2, and you need to check if risk level 3 is eligible, you would:
1. Query the table u_tier_risk_mapping where u_tier_level is T2.
2. Fetch the results and check if risk level 3 is within the set of returned u_eligible_risk_level by your query.
### Step 4: Implementing the Check in a Business Rule or Script Include
You can embody this logic in a Business Rule, Script Include, or even a Flow Designer action, which will be triggered at the relevant point in your process (e.g., upon item creation, update, or at a specific workflow step).
Here is a conceptual approach for a Script Include:
var TierRiskValidator = Class.create();
TierRiskValidator.prototype = {
initialize: function() {},
isRiskLevelEligibleForTier: function(tierLevel, riskLevelSysId) {
var gr = new GlideRecord('u_tier_risk_mapping');
gr.addQuery('u_tier_level', tierLevel);
gr.query();
while (gr.next()) {
if (gr.u_eligible_risk_level.sys_id == riskLevelSysId) {
return true; // Risk level is eligible for this tier
}
}
return false; // Risk level is not eligible for this tier
},
type: 'TierRiskValidator'
};
//This is Risk LevelEligibleForTier method returns true if the risk level is eligible for the specified tier level, according to your mapping table.
Note: Please Mark this Helpful and Accepted Solution. If this Helps you to understand. This will help us a lot.
Thanks & Regards
Deepak Sharma