- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2024 10:35 AM
Hi Team,
Create a 2 fields in the Custom table:
Risk Level: choice[Critical, High, Medium and Low]
Barr Level: String Only set Value[Critical, High, Medium and Low]
Requirement: compare the Barr Level is Higher then the Risk Level.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2024 08:53 PM
you can use a Business Rule or a Script Include to compare the values of the "Risk Level" and "Barr Level" fields whenever a record is inserted or updated in the custom table.
(function executeRule(current, previous /*null when async*/) {
// Get the values of Risk Level and Barr Level
var riskLevel = current.getValue('risk_level');
var barrLevel = current.getValue('barr_level');
// Map the text values to their corresponding numerical values
var riskLevelValue = getNumericValue(riskLevel);
var barrLevelValue = getNumericValue(barrLevel);
// Compare the values
if (barrLevelValue < riskLevelValue) {
// Barr Level is lower than Risk Level
gs.addErrorMessage("Barr Level cannot be lower than Risk Level.");
current.setAbortAction(true); // Abort the transaction
}
// Function to map text values to numerical values
function getNumericValue(level) {
switch (level) {
case 'Critical':
return 4;
case 'High':
return 3;
case 'Medium':
return 2;
case 'Low':
return 1;
default:
return 0; // Default value or error handling
}
}
})(current, previous);
Please Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2024 03:57 PM
- Create a new field to display the result (higher, lower, same).
- Open the dictionary for the created field. Press 'Advanced view' from the Related Links if not already in advanced view.
- Go to the calculated value tab and check the 'Calculated Value' checkbox. Put in the following script:
(function calculatedFieldValue(current) {
var ranking = {
'Low': 1,
'Medium': 2,
'High': 3,
'Critical': 4
};
var field1Rank = ranking[current.getDisplayValue('field1')];
var field2Rank = ranking[current.getDisplayValue('field2')];
if (field2Rank > field1Rank) {
return 'Field 2 is higher than Field 1';
} else if (field2Rank < field1Rank) {
return 'Field 2 is lower than Field 1';
} else {
return 'Field 2 is the same as Field 1';
}
})(current);
Your newly created field will now hold a string value saying if field2 is higher, lower or the same as field1.
You can also just make it a true/false field of course and call it Higher: true/false.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2024 08:53 PM
you can use a Business Rule or a Script Include to compare the values of the "Risk Level" and "Barr Level" fields whenever a record is inserted or updated in the custom table.
(function executeRule(current, previous /*null when async*/) {
// Get the values of Risk Level and Barr Level
var riskLevel = current.getValue('risk_level');
var barrLevel = current.getValue('barr_level');
// Map the text values to their corresponding numerical values
var riskLevelValue = getNumericValue(riskLevel);
var barrLevelValue = getNumericValue(barrLevel);
// Compare the values
if (barrLevelValue < riskLevelValue) {
// Barr Level is lower than Risk Level
gs.addErrorMessage("Barr Level cannot be lower than Risk Level.");
current.setAbortAction(true); // Abort the transaction
}
// Function to map text values to numerical values
function getNumericValue(level) {
switch (level) {
case 'Critical':
return 4;
case 'High':
return 3;
case 'Medium':
return 2;
case 'Low':
return 1;
default:
return 0; // Default value or error handling
}
}
})(current, previous);
Please Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks