Checking phone configuration in an ODK form

I'd like to share a technique to perform basic phone configuration checks within an ODK form. I've learned this from one of our partner organizations, and it seemed so broadly useful that I'm taking the liberty to share it here.

The idea is to add a set of configuration checks at the beginning of a form, like this:

type name label::English (en) required relevant
start start Start of Survey
end end End of Survey
username username Enumerator User Name
deviceid deviceid Device ID
phonenumber phonenumber Enumerator Phone Number
begin_group group_check_constraints Checking phone configuration
note note_missing_username :stop_sign: Missing user name yes normalize-space(${username}) = '' or ${username} ='NULL' or ${username} = NULL
note note_missing_phone_number :stop_sign: Missing phone number yes normalize-space(${phonenumber}) = '' or ${phonenumber} ='NULL' or ${phonenumber} = NULL
note note_incorrect_date_and_time :stop_sign: Incorrect phone date/time yes date(today()) < date('2022-06-01')
end_group

These checks will not allow data collection to proceed unless the phone configuration satisfies certain minimal constraints.

The attached file contains a more complete example, with hints that explain how the problems can be fixed.
odk-configuration-checks.xlsx (11.5 KB)

4 Likes

Great Work
THANKS HELPFUL TRICK FOR SURVEY

Thanks for sharing this, @Sjlver!

I'm surprised that you'd need to check for 'NULL' or NULL. Have you actually seen examples of devices that produce these values?

No. To be honest, I used this pretty much as I've seen it in our partner's forms, and decided to keep the check.

I guess it could happen through some QR code configuration issue (but is the user identity even configurable via QR code?)... but we might as well remove these parts of the check.

It's unlikely, maybe even impossible, that you'd get either NULL value. ${username} = '' is all you really need for that relevance check.

normalize-space() doesn't help much because it only strips leading and trailing whitespace and leaves at least one space.

1 Like

Thanks for sharing this - I have used the simplified Relevance of ${username} ='' as suggested by @yanokwa and in the hint I have given instructions as to how to change the setting...

However, I was expecting this Note to disappear once I had added a username to the Project... This doesn't happen. Also the draft form always shows the Relevant message when re-opened. New forms created after the username has been set do not show the message (so I know it is working :slight_smile: )

I wonder how to trigger the username field to update? I tried saving the form as draft and then reopening it, hoping that it might act like an expression: https://docs.getodk.org/form-logic/#when-expressions-are-evaluated - no joy

I'm not sure that I can 'trigger' a calculation on metadata / hidden question within the form?

To test this I changed the 'relevant' Note to a Trigger question type (intending for the enumerator to confirm that they had completed the task). I then changed the Username question to have a calculation of 'username' and the trigger to be the Trigger question (sorry that's a rabbit hole!). Sadly that doesn't work either.

Is this a feature? Not one I like :slight_smile: and potentially it confounds the usefulness of including these checks (I haven't made my Relevant question Required, but if I had, I would be unable to submit the data within the form...)

I have also tried a number of 'constraints' on the username column and can't get them to work - maybe they are not checked as they can't be changed by the enumerator in the form...

Any help gratefully received. As always...

CONTEXT: The inclusion of username is useful to me because it helps segregate data by the device used (I have, in other circumstances, used a 'please give your name' question, and had the default as 'last saved', but it's an extra question...). In this case I have a live form where new devices are being distributed with a shared QR code for a 'group' app user so I want to be able to differentiate based on username (an existing field). I don't want to set up bespoke QR codes for each app user with a username included, partly as it's too hard for my little brain, partly because I'm lazy and then need to do that for each device, and I also can't predict every permutation for app users - username is clean, simple and unobtrusive (once you know how to set it).

Hi Chris,

I use an intermediate calculation and it works (the tip disappears when metadata is set)
Here is a block dedicated to user name and user mail questions.

We use the metadata fields and last-saved values to prefill the questions :

authentication.xlsx (21,7 Ko)

Hi Mathieu,
Thanks for your suggestion. I'm not sure it's working as you intended (or at least not on my rubbish old Sony phone :slight_smile: ). Because the 2 questions are required (name and email), you can't advance anyway, but if you fill both of them, but don't add username in the metadata the 'Tip' still disappears...

Your form also behaves in the same way as my form- if you save a draft, then add username, when you (re-)open the draft username is not updated.

Here is the csv file from 3 forms I submitted on my server using your form definition authentification.csv (873 Bytes)

row#4 is the first (no username) submitted at 2023-07-18T16:37:13.091Z
row#3 is the 3rd form, started after I entered a username; submitted at2023-07-18T16:36:13.526Z
row#2 is the second form - I started the form with blank username, saved draft, then added metadata, opened the draft form and submitted: 2023-07-18T16:37:23.948Z (having started and submitted the 3rd form in between to make sure!)

The Tip did not show when I started form from row#2 (which had name and email pre-filled from #last-saved, but no username), or when I started the form from row#3 (as you were expecting). But only 1 has username.

Sorry, I hate doing the 'I think you'll find that's not the case' when you've tried to help, but...

I think you'll find that's not the case :face_with_open_eyes_and_hand_over_mouth:

At least I did have to try it to be sure - a null outcome is still an outcome :slight_smile:

Tentatively I might say that it looks like the 'trigger' to update username either doesn't exist or doesn't work for an existing draft (or open) form... I wonder if that's the case for any other metadata fields? Haven't tested those (usually I'm not interested in the DeviceID or phone number) - I guess that it's not usual to update metadata on existing forms, but as I'm trying to make sure that people complete that, I need it. My current 'work-around', by default is to have a copy TEST form as a training sandbox, which has this question, so as long as enumerators play with the test before they start real data collection it might be ok... But I have no way to 'enforce' unless I give them an 'endless loop of doom' and they 'duck-out' of the form without saving it as a draft?

Hope you are well and not too hot...

I think I misunderstood your problem :frowning:

I am also interested in a solution to force my colleagues to fill the metadata in Collect !

In the North for a couple of weeks. Not so hot for the moment;

Good evening Chris,

Maybe you'll find me you'll find me stubborn :slight_smile: but as I said I am also interested to find a beginning of solution.

What about this workaround : groups and questions are hidden until the metadata is filled.
So enumerators can't fill the form nor send real data to the server (or at least an empty form).

authentication.xlsx (21,4 Ko)

If the submit the form, you will be able to filter the data with the "acknowledge" question...

Hi Mathieu,
I love stubborn!

This looks like a serene work around - presumably we end up with a few 'null' records, but as you say, we can filter those on Central (and maybe one day even delete them :slight_smile: ). I'll stick with my 'sandbox' version for now, although yours is better for a new form (I'm trying to retrofit existing dataset, so wouldn't need to change my existing form except maybe to give a doom laden warning about losing data)...

Hopefully the core team can come in on this to explain if we're doing something wrong, or naughty.... Heads up @yanokwa

1 Like