Constraint not being honored

1581
6
Jump to solution
02-28-2021 03:05 PM
ShelbyZelonisRoberson
Occasional Contributor III

Hi -

I've built a survey in Connect (3.12) and I'm having trouble with one part of it. My end goal is to have the survey PREVENT submission if a geocoded address field (${matchaddress} is null. Seems easy right? I thought I could create a select_one yes/no ${validaddress} field, calculate it to be 'no' if ${matchaddress} is null and 'yes' if ${matchaddress} is not null, and put a constraint on this field so that it will not let the user submit a record if ${validaddress} = 'no', but it doesn't work. It lets me submit a record even if the matched address is null and validaddress is no. I've also tried various iterations of this using ${matchaddress} = null, since it should have the same result. No dice.

What's weird is that if I put ${matchaddress} = 'null' in the relevant column, the ${validaddress} field either shows or doesn't show exactly as it should. So why isn't the constraint working the same way? I've worked on this for days and days and I feel crazy and I'm really hoping someone on the Survey123 team can briefly work with me and take a look. I'd prefer to email my XLS rather than share here.

Thank you!

0 Kudos
1 Solution

Accepted Solutions
ShelbyZelonisRoberson
Occasional Contributor III

I played around a lot with this using both 'null' and '' as suggested by Doug.

The thing that finally worked:

1. Delete the validaddress field altogether - for some reason this seems to have been throwing it off

2. Set the constraint on matchaddress to be ${matchaddress}!='null' (also removed previous expression in the relevant column). I tried a constraint for ${matchaddress}!='', but the geocoder is indeed returning 'null'. 

View solution in original post

6 Replies
DougBrowning
MVP Esteemed Contributor

Have you tried required?  Constraints cannot test for blank '' since it could be a relevant hiding.  When a question is blank in 123 it gets '' not null.  Null is not used.

Hope that works.

0 Kudos
ShelbyZelonisRoberson
Occasional Contributor III

Yep I've tried required on a variety of the fields to try and get it to not allow submission but I haven't found a solution where it works properly. As for nulls... I'm not sure if the matchaddress question is coming up blank or truly "null" because it's reaching out to a geocoder, matching an address, and returning the matched address. If it doesn't find an address, I'm not sure what it comes back with. I assumed the matched address field was coming back as null when no address was found, because the relevant column ${matchaddress} = 'null' works as I expect it to.

I'll try playing around with '' - thanks!

0 Kudos
ahargreaves_FW
Occasional Contributor III

@DougBrowning if a question in blank in Survey123 and gets '' why won't the below constraint work for to force the user to enter a value?

string(${REST_TYPE})!=''

 

(Note:  {REST_TYPE} is inside of a repeat...unsure if that matters?)

0 Kudos
DougBrowning
MVP Esteemed Contributor

Why are you using string()?  Is it a number field?  Is it a select multiple?

I have seen it be picky on some field types.  Also make sure to have spaces in there just in case.

try some of these options

${REST_TYPE} != ''

${REST_TYPE} != ""

string-length(${REST_TYPE}) != 0

string-length(${REST_TYPE}) > 0

If a select try

count-selected(${REST_TYPE}) != 0

count-selected(${REST_TYPE}) > 0

hope one of those does it.

0 Kudos
DougBrowning
MVP Esteemed Contributor

I have never used geocoder so not sure exactly what it returns.  Usually if I do not know I create a note or text field to show the value then I know exactly what it is.  Then test for that.

0 Kudos
ShelbyZelonisRoberson
Occasional Contributor III

I played around a lot with this using both 'null' and '' as suggested by Doug.

The thing that finally worked:

1. Delete the validaddress field altogether - for some reason this seems to have been throwing it off

2. Set the constraint on matchaddress to be ${matchaddress}!='null' (also removed previous expression in the relevant column). I tried a constraint for ${matchaddress}!='', but the geocoder is indeed returning 'null'.