Creat Business Rule for counting multi row Variable set

nadavt182355205
Tera Contributor

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

 

 

nadavt182355205_0-1724143438968.png

 

nadavt182355205_1-1724143468549.png

 

2 REPLIES 2

Sid_Takali
Kilo Patron
Kilo Patron

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); 

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?