CommCare – How to Use jr:itext Logic to Display Question Answers on a Label

commcare

I am trying to set up jr:itext logic to pull question answers from my app and display them on a label. I've followed the instructions in the CommCare documentation and I've ensured the correct question path is being used for what I want to display. However on the device when I deploy my app all of my jr:itext logic shows as: [itext:ql_notification_details/patient_type_choicenew-label]

What is the best way to troubleshoot this error? Am I missing something in my jr:itext logic if I'm using exactly the logic displayed in the documentation?

Best Answer

If you're trying to display answers in labels then you should be able to directly reference them with something like this (where the question_id is ask_this)

<output value="/data/ask_this" />

If you're wanting to display the label of a choice in a later output (e.g. you're storing the choice value as a case property but it's different from the label used, and you need to selectively display the label again later then something like this:

<output value="jr:itext(concat('ask_this-', /data/ask_this, '-label'))" />

edit: if your question isn't at the top level then you'll need to reflect the path as such: folder/ask_this and /data/folder/ask_this
additionally, if you're wanting to save this as a hidden variable (e.g. using it in a calculate condition) then remove the "output value" wrapper and only use the bit between the double-quotes (not including the double-quotes)

That being said, it looks like your "error" might actually be the output of a jr:itext phrase when the /data/here component is null. Perhaps you've done what I did: set up a feed from a multi-choice question and thought you had an error, but it's actually because you've just not selected an answer yet?

Additionally, you might be missing a dash, either following "_choicenew" or preceding "label" I say this because if you've made the "null" error as I did, then I'd expect to see two dashes there, rather than one.

Other non-flattering troubleshooting for me was (quite some time into researching your question) reading to the end of the documentation and realizing that I'd not replaced all the "place-holder" text (I'd left in the first question).

Additionally, I opened up the raw XML via the "edit source XML" option to have a look at the way jr:itext is implemented in the raw code.