Hello. We are using Survey123 forms for volunteers to register for a cleanup event. We are including in the from a place for the volunteer to choose Tshirts by several sizes. I want to restrict the total of the Tshirt values by size chosen by the volunteer to not be greater than the total number of volunteers. (Example: if there are 3 volunteers they should not be able to choose 4 or more tshirts on the form). Each Tshirt by size (example., TShirtS, Tshirt2XL, etc) field is an integer and there is a Total Number of Volunteers field that is an integer as well.
I tried this and it didn't allow ANY number.
(${TshirtS})+(${TshirtM})+(${TshirtL})+(${TshirtXL})+(${Tshirt2XL})+(${Tshirt3XL})+(${TshirtYM})+(${TshirtYS})<=(${NumberVol})
I feel like I'm on the right track. Please advise.
Thanks,
Shari
Hi Shari,
Could you attach your XLS form so we can look into the issue a little more?
Thanks,
-Barbara
Hi Barbara. I don't see where I can attach a file. I'd be happy to send it to you.
Hi Shari,
Thanks for the XLS sheet, I was able to submit a survey if the quantity of shirts was less than the total number of volunteers and an error was returned on submit if the number of shirts was greater than the number of volunteers. Based on that I think the logic of the constraint is working as it should and that it may be another factor that that's preventing data entry. Did the shirt size fields return a validation error or were you unable to enter any value into the fields?
Also, will people be creating new surveys or accessing pre-generated ones from the inbox? I did notice that the contact info group is set to read only, which would probably prevent people from submitting a new survey since some of the fields in the group are required.
-Barbara
Thanks for checking and working with me on this.
So this is correct?
${TshirtS}+${TshirtM}+${TshirtL}+${TshirtXL}+${Tshirt2XL}+${Tshirt3XL}+${TshirtYM}+${TshirtYS} <=${NumberVol}
I tried again and I got an error that I need to enter a valid number. I had entered "1". Also I have default values of "0" and they also were shown as Not valid data. Maybe I don't have the equation in the correct field? Which field in the XLSForm should contain the above equation.
You could create a calculate question to generate the total number of t-shirts and then constrain against that field. If you enter ${TshirtS}+${TshirtM}+${TshirtL}+${TshirtXL}+${Tshirt2XL}+${Tshirt3XL}+${TshirtYM}+${TshirtYS} into the calculation field and then enter ${totalTshirts}<=${NumberVol} into the constraint section it should provide the validation you need on submit.
In my initial testing I entered the formula you provided directly into each t-shirt field. The validation worked, but since each field constraint evaluates the sum of all fields and the 'adult small' field is evaluated first, the validation error is always shown on the 'adult small' field, even if it's 0. I'm not sure if that's the approach you took too, but it's one possibility for the behavior you're seeing.
Thanks,
-Barbara