Creat Business Rule for counting multi row Variable set
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2024 01:46 AM
Hi,
i need to make a Business Rule that is take all the values (1-5) from the multi row variable set and calculate the avrage of all the the variable by multiply all the values and then divide by the number of the values.
For example if i have the values 1,2,3 then i need to multiply 1*2*3=6 and then divide by 1.
The user can insert more then 1 row of values, for example 1,2,3 and 4,5,6 each 3 values are part of the multi row variable set that users can insert.
After the numbers are calculated i need to change a field in the form name "risk" to a value:
1-15 - low
16-44 - med
45 and higher - high
i need help to write the business rule.
thank's
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2024 03:01 AM
Hi @nadavt182355205 Try below code
var rows = getMultiRowVariableSetValues();
var productSum = 0;
var numRows = rows.length;
rows.forEach(row => {
var values = row.values;
var product = values.reduce((acc, value) => acc * value, 1);
productSum += product;
});
var average = (numRows > 0) ? (productSum / numRows) : 0;
var risk;
if (average >= 45) {
risk = "high";
} else if (average >= 16) {
risk = "med";
} else {
risk = "low";
}
setFieldValue("risk", u_risk);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2024 03:08 AM
hi,
on what table to set the Business Rule?
and the first row is for getting all the the variables? how i know it is for my form?