ODK 2.0 - looking up choice display.title.text

Is there any guidance on how to do the equivalent of:

jr:choice-name(${var}, ‘${var}’)

in ODK 2.0, to return the label associated with a particular code?

Thanks
Jason

Hi Jason,

The way to get the choice values in Javascript in ODK 2 is the getColumnChoicesList function in the odkData API.

You can see the API here on Github. You can read more about choices in the Javascript API on our specification here (search for “choices --”). You can read more about choice list definitions in our XLSXConverter documentation.

Hope this helps.

Regards,
Jeff Beorse
Eir Birch LLC

Thanks Jeff,

That is really helpful. I’ve tried using it in a number of different ways but I haven’t had any luck yet. Usually the error I get is something like “getColumnChoicesList is not defined”.

I’m still getting familiar with JS so I’m probably using it in the wrong context or something, can you provide a usage example?

Thanks
Jason

Is someone able to provide a syntax example on how to use this?

Thanks
Jason

Hi Jason,

So sorry I lost track of this thread.

Are you making a Tables app or is this code in Survey? I’ve been assuming you are using Tables.

Are you including odkData.js in your HTML head? You should have a line like:

<script type="text/javascript" src="../../system/js/odkData.js"></script>

inside the head tag in your HTML file.

If you could send an example of what you’re trying to do I can do a better job at helping.

I didn’t find any examples in our existing code. I’ll look at messing with one of the existing example apps to make a code example for this.

Regards,
Jeff

No worries, thanks Jeff.

I was trying to use this within the context of Survey, maybe in a calculation assign or something. I investigated the index.html file at app\system and it has odkData.js in the head. Maybe that is the wrong html file, or maybe this is not an appropriate use-case.

Anyway, I’m coming at this from the viewpoint of ODK 1.0 and I’m definitely still trying to understand how all these pieces fit together. It’s been a struggle parsing the various bits and pieces of documentation. I haven’t really even looked at tables yet, it has just recently occurred to me that I might need it so that will probably be the next step for me.

Thanks
Jason

Ah, my mistake in assuming you were using Tables.

For Survey I asked for @clarice_larson to help find the appropriate function, and we weren’t able to find anything that takes a choice value as an argument and returns the display name of it. Maybe you could give me a bit more context about what you’re trying to do?

Sorry about the current state of affairs with our website and documentation. Its in transition now and we’re in the process of cleaning it up. In the meantime, the best available documentation for the ODK 2.0 tools is here.