- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2024 10:02 AM - edited 02-21-2024 10:05 AM
Hi All,
I am trying to calculate impact field in change request form based on the two fields (Customized fields) both are choice fields each field has choices. I am trying to assign values to each choice when user select the choice and based on the total of the value the impact field should get populated. Below is my script which i have given in Risk condition, but its not working.
(function executeRule(current, previous /*null when async*/) {
var aValue = current.u_impact_during_implementation.getDisplayValue();
var bValue = current.u_impact_of_failure.getDisplayValue();
// Map choices to their corresponding values
var valuesMap = {
'no_impact': 10,
'degradation': 60,
'loss_of_service': 60,
'service_outage': 95,
'minimal_failure': 10,
'moderate_failure': 70,
};
// Calculate total value
var totalValue = valuesMap[aValue] + valuesMap[bValue];
// Set impact field based on total value
if (totalValue <= 50) {
current.impact = 3; // Low impact
} else if (totalValue <= 80) {
current.impact = 2; // Moderate impact
} else {
current.impact = 1; // High impact
}
})(current, previous);
Please suggest.
(function executeRule(current, previous /*null when async*/) {
var aValue = current.u_impact_during_implementation.getDisplayValue();
var bValue = current.u_impact_of_failure.getDisplayValue();
// Map choices to their corresponding values
var valuesMap = {
'no_impact': 10,
'degradation': 60,
'loss_of_service': 60,
'service_outage': 95,
'minimal_failure': 10,
'moderate_failure': 70,
};
// Calculate total value
var totalValue = valuesMap[aValue] + valuesMap[bValue];
// Set impact field based on total value
if (totalValue <= 50) {
current.impact = 3; // Low impact
} else if (totalValue <= 80) {
current.impact = 2; // Moderate impact
} else {
current.impact = 1; // High impact
}
})(current, previous);
@Amit Gujarathi @Dr Atul G- LNG
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2024 12:02 AM
Thank you @Aman Kumar S ,
Yes i picked up incorrect API there , corrected it and its working fine now . Thank you once again .
Thank you @Dr Atul G- LNG
==============================================================================
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var aValue = current.getValue("u_impact_during_implementation");
var bValue = current.getValue("u_impact_of_failure");
gs.log("A Backend value :"+aValue);
gs.log(" B Backend Value :"+bValue);
var valuesMap = {
'no_impact': 10,
'degradation': 60,
'loss_of_service': 60,
'service_outage': 95,
'minimal_failure': 10,
'moderate_failure': 70,
};
// Calculate total value
var totalValue = valuesMap[aValue] + valuesMap[bValue];
gs.log("getting total value sum"+totalValue);
gs.log("A value in number :"+valuesMap[aValue]);
gs.log("B value in number :"+valuesMap[bValue]);
// Set impact field based on total valuex
gs.log("Total of A and B value : "+totalValue);
gs.log(" Testing 123");
if (totalValue <= 50) {
gs.log("testing 1");
current.impact= 3; // Low impact
}
else if ((totalValue >50)&&(totalValue <=80))
{
gs.log("testing 2");
current.impact = 2; // Moderate impact
}
else if(totalValue>80)
{
gs.log("testing 3");
current.impact = 1; // High impact
}
current.update();
})(current, previous);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2024 12:05 AM
Great it worked out for you, feel free to mark my response as correct so it ends up in solved queue
Aman Kumar