Comparing fields in a table
I have a table in a form and would like to compare one field in the table to another field on the same row. for example: Col0, Col1, Col2, Col3
Want to compare each row if Col3 > Col2 or Col1 - error message
When I create the rule, only the last row gives the error message, the other rows do not display the error even though Col3 is > Col2 or Col1. How do I get all rows to display error message ?
0
-
Official comment
Hi Rita!
Great question. While the rule builder "error text" only applies to the whole table, you can add a message control column that's set to appear via a business rule(below). A couple of tips:
- Check "hide label" on the message column
- On the cell level of the message column, set a BG color to something that will pop. We used #ffcccc
- In our example we also set the table error text, but that can be left out if the row error message is sufficient
How it will look when tested:
Business Rule:
var Col0_start_index = Table1Repeat.itemAdded ? Table1Repeat.itemIndex : 0;
var Col0_end_index = Table1Repeat.itemAdded ? Col0_start_index+1 : Col0.value.length;
var event = form.load;
Message2.visible = false;
for (let i=Col0_start_index; i < Col0_end_index; i++) {
if (((Col0[i].value >= Col1[i].value) || (Col0[i].value >= Col2[i].value)) && (Boolean(Col1[i].value)) && (Boolean(Col2[i].value)) && (Boolean(Col0[i].value))) {
Message2.visible = true;
Message2[i].value = 'Incorrect Value Col0 cannot be more than Col1 or Col2';
Col0[i].status = 'Incorrect Value: Col0 cannot be more than Col1 or Col2';
}
else {
Message2[i].value = ' ';
}
} -
Thank you....works perfectly
0
Please sign in to leave a comment.
Comments
2 comments