In a text input screen (type 5) I have a drop down input element (answer type 6) with several answer items. On leave OK I want to store the selected answer item's label in a local variable. Calling getAnswerData gives me the answer item's client key instead. How to get access to the label instead?
What you can do is to use getAnswerValue in the onLeaveOkPersistAssignment and allocate this value in a new local var e.g. $local:selectedItem. By doing so the clientKey will be stored in this var. On the next or follow up screen you can use this clientKey to access the right array pos value.
Example: Initially your question could look like this:
question key="q0" type="5" title="">
<answer key="q0a0" nextQuestionKey="q1" dummyAnswer="true" attributeType="6">
<item clientKey="0" dummyAnswerItem="true" />
<text/>
</answer>
<onEnterAssignment>
$local:myArray =
{
0:'Product 1';
1:'Product 2';
2:'Product 3';
};
addAnswer($answer:'q0a0', null, 'Dropdown List');
for(items:$local:myArray)
{
addAnswerItem($answer:'q0a0', null, '0', items, $local:myArray[items]);
}
</onEnterAssignment>
This example contains a dummyAnswer(key=q0a0) and a dummyAnswerItem, in the onEnterAssignment you are calling the answer in use of addAnswer() and allocate the answer items in use of addAnswerItem. Now in the onLeaveOkPersistAssignment of this answer you are using getAnswerValue(), in use of getAnswerValue you are assigning the clientKey to the local var.
<onLeaveOkPersistAssignment>
$local:selectedItem = getAnswerValue($answer:'q0a0');
</onLeaveOkPersistAssignment>
What you can now do is this on the same screen in use of changeEvents or on a follow up screen:
<question key="q1" type="0" title="">
<answer key="q1a0" nextQuestionKey="END" dummyAnswer="true"/>
<onEnterAssignment>
addAnswer($answer:'q1a0', null, $local:myArray[$local:selectedItem]);
</onEnterAssignment>
</question>
This allows you to print the label of the selected item on the next screen.