I have an editable grid containing two drop-down columns with other editable columns as well.
In grid, one drop-down value is mapped with another drop-down value. I need to put a validation that if that particular mapping already exists in DB then show mapping already exists only on click of submit button.
Let's say in DB values in one row are:
A (drop-down 1) B (drop-down 2) C (Text field)
1 2 xyz
Then if user enters the same mapping of A and B, i.e. selects A as 1 and B as 2 in UI, then show mapping exists.
User can add multiple rows in editable grid through add row button and multiple mappings in grid can be added. It should be able to check for all rows and throw validation on row components where duplicate exists in DB.
Discussion posts and replies are publicly visible
You can use validationGroup to run the validation only on the button click and to validate you can query the data into one variable and insert the grid data into seperate variable and there you can put your logic to check whether the data is available into DB or not.
When should I fetch the data from DB to compare with grid data, is it on click of submit or at form load.
There are multiple users who can create a mapping request. Let's suppose one user trying to create a mapping but before he submits that mapping, another user already submitted the same and now when first user started the mapping the mapping was not in DB but now when he clicks on submit it is there because another user submitted the same before him.
How do you handle this concurrency situation.
Another question, I am unable to use validation group. Can you help with the logic. When I call the validation in validations parameter, then it checks before submit or in parallel to user entry.
on button click, you can use query entity to fetch the data and store it in variable and then check whether the value is available in that variable or not for the same which you are trying to insert
For Validation group: Use Validation Groups for Buttons with Multiple Validation Rules - Appian 22.3
I have this doubt where do I call this validation rule which checks the combination of multiple fields for any duplicates.
Do I need to call this rule in each field component of combination in grid or is there any other way around.
Let's suppose it's combination of column A and column B I am checking, do I need to call the rule in both A and B components. If so how, especially in case of editable grids?
under validation configuration of the grid.
How can I show which row and which columns have got the error, then only grid level validation is not sufficient?
In that case you can use the validation on the respective fields.
a!localVariables( local!data, a!gridLayout( headerCells: { a!gridLayoutHeaderCell(label: "1"), a!gridLayoutHeaderCell(label: "2"), }, addRowLink: a!dynamicLink( label: "Add", saveInto: { a!save( local!data, append(local!data, { a: "", b: "" }) ) } ), rows: a!forEach( items: local!data, expression: a!gridRowLayout( contents: { a!textField( value: fv!item.a, saveInto: fv!item.a, validations: if( count( intersection( wherecontains(fv!item.b,local!data.b), wherecontains(fv!item.a,local!data.a) ) ) > 1, "Error", "" ) ), a!textField( value: fv!item.b, saveInto: fv!item.b, validations: if( count( intersection( wherecontains(fv!item.b,local!data.b), wherecontains(fv!item.a,local!data.a) ) ) > 1, "Error", "" ) ) } ) ) ) )