In my form, I have a question that is supposed to get an ID. This ID is used to fill other information in the same form. I already have the list of possible IDs in a CSV file and by default, a non-existing ID will simply not fill the other elements. I would like to implement a constraint system in which the ID is checked against the existing list from the CSV file and if not found in there, an error will occur. Is that possible?
I just edited my post and attached the XLSForm. As for your previous question, yes, the ID is a mandatory field (in yellow in my XLSForm). I already put a constraint to accept only 9 characters, which is the number of characters for all the IDs, so the remaining constraint I need is for it to check from my CSV list of IDs whether an ID was found or not.
In my form, you will see that it does six pulldata functions which are for two different purposes:
The first 3 functions (code_lv1, code_lv2, code_lv3) pull the identification code for each level, which I will use for everything analysis wise (they are numbers so it’s easier for my coding),
The last 3 functions (lv1, lv2, lv3) pull the labels corresponding to the ID and print them in the notes for verification by the data collector.
My CSV file contains around 500 ID codes along with each level’s codes and labels corresponding to each of them.
If you enter your ID, it pulls your SIX data/functions and prints the data in the notes. So, if you find data in the notes, it means the function is working. If no data is showing, it means the function is not working.
Therefore, you need to fix the ID constraint to be less than 500 (as per your requirement).
I believe fixing the ID constraint will suffice, and there is no need to check the ID again.
Thanks for your insight @Bulbulrds, but that is not quite what I am looking for. You see, in my CSV file, there are exactly 480 places with their corresponding ID. They are unique and follow a certain geographical logic. However, for example, I can have an ID of 808707606, then followed by 808707604, meaning that 808707605 is not a registered place. The reason I am stating this is in case the solution would be to set up a simple constraint that the ID should be between two values. It can work and probably avoid a lot of potential mistakes, but it won’t solve the biggest part of it in my opinion. People could mistype the last character and that would be a fitting ID, though it doesn’t return any value.
Thanks,
So, I have given thought on this and came with a temporary solution. It’s not what I am looking for, as I want to implement a constraint, which means that the form will not be submitted unless an existing ID is found.
This is a work around, and therefore does not block my submission in case of a non-existing ID, but rather simply informs the user whether a matching ID was found or not (which is better than nothing).
Add one calculate function that will use pulldata. Make it pull the ID itself from the CSV.
Add two different notes for the two possibilities (finding a matching ID or not finding a matching ID). Add relevant code for each of them considering that pulldata will return ‘’ (empty) in case of a not found match. Something such as: ${pull_data_returned} !=‘’ and ${pull_data_returned} =‘’
This is not a solution yet though, just sharing it here in case someone else is looking for a work around. I am still hoping to see what I need.
Hi @kevin_razafindrabe,
Nice work. I used this system in my project in 2022 with a few changes. I stated that if no matching data is found, a note is displayed, and this note is mandatory (the ‘required’ attribute is set to ‘true’). Because of this, when the ‘not found’ note is displayed, the form cannot proceed and cannot be submitted.
In your form, if ‘show_id_2’ is mandatory (the ‘required’ attribute is set to ‘true’), then the form cannot be submitted without a correct ID.