Help with randomization error code

Dear KoboToolbox Community,

I hope this message finds you well. My name is Eduardo, and I am a student at Harvard University.

I am currently designing an XLSForm where each respondent is randomly assigned two different guides (images) from a set of 20 and then asked a series of feedback questions about each. My goal is:

  1. To randomly assign each respondent two distinct guides using calculated fields.

  2. To ensure the selected guides are displayed as images before respondents answer related questions.

  3. To include conditional logic so that follow-up questions only appear based on the respondent’s answers.

However, I keep encountering the following error:

FormLogicError: Could not evaluate: First assigned guide, message: not sure how to handle expression called on nodeset that doesn’t start with a ‘/’: assignedguide{“stack”:[{“t”:“root”,“tokens”:[{“t”:“arr”,“v”:}]}],“cur”:{“v”:“assignedguide”}}

I suspect the issue is with how I am implementing the randomization and selection of images within my XLSForm. Specifically, I am using:

• calculate random1 = once(int(random()*20)+1) to generate a random number between 1 and 20.

• calculate random2 = once(int(random()*20)+1) while ensuring it does not equal random1.

• choice_filter=“number=${random1}” to match the randomly generated number to an image in the choices sheet.

Despite these efforts, the error persists, and I am unable to preview the form.

I have attached my XLSForm for reference and included the link to my form: [Insert KoboToolbox Form Link]

Any guidance on fixing the randomization logic and ensuring that each respondent is assigned two different images correctly would be greatly appreciated.

This is a link for the code I used: [DraftForm.xlsx - Google Sheets]

Thank you in advance for your help!

Best regards,

Eduardo

For starters, you appear to have these calculations in the wrong column (appearance), whereas all calculations should be put under a calculation column. See XLSForm Docs

I might suggest reading thru the XLSForm spec to make sure you understand what each of these columns are used for, and how. There is also good documentation on writing form on our support website: Creating Forms — KoboToolbox documentation

… while ensuring it does not equal random1.

This is also a lot trickier in reality than you might think… It is easy to generate a random number. But it is hard to generate another random number and guaranteed it will never be equal to your first! [and again, your usage of the relevant column here to attempt to do this is incorrect; see relevant to understand what this column is actually used for]

1 Like

Hi! Thank you for your help.

Now my form can be deployed. However, the image in the uploaded form does not load. It stays with a question mark. Can you please help me?
Link for the form: XLSform code

Link to view form: https://ee.kobotoolbox.org/x/Pdkd4HTl

In the form preview, the images load perfectly however. I deeply appreciate your help.