Visual Flow “Choices” have a cute little “Show Input on Selection” option where if you click the checkbox, when the user selects that choice a little text field will appear for them to input some text. The question is, how do you gain access to the information that is entered into this box to output to the screen?
When you setup a choice you have the option of adding a stored value. In this example I have a constant, named “AddLocationC”, as the stored value.
The “Show Input on Selection” box is checked so when the user clicks on this choice a little pop-up text box appears with the words “Enter a New Location” to its left.
What happens behind the scenes is the stuff the user types into the text box now becomes the stored value of the choice.
What’s interesting, though, is that if you try to output to the screen the value that was entered, you’ll get the default stored value and not the stuff that was entered into the little box.
So how in the world do you output the text string that was entered into that little pop-up field to the screen? If you output the Screen Choice Field value you get the Choice default stored value (not the input text). And if you output the Choice, you get the same thing (yes, logical, I know, but nevertheless, you never know!).
I found the answer in a round about way as it doesn’t seem to be readily available in any of the SF-sponsored literature.
It seems that the text is sort of buried under the default stored value, and if you assign the choice to a variable, Wha La! it becomes available. I call it Choice-Laundering!
Here is a possible usage case for this nifty little field.
I want the user to be able to fill out a Location field in one of three ways:
- Indicating there is not a location
- Selecting from a list of locations
- Entering a new location
The “NoLocation” choice is a simple Choice that returns an empty string:
The “Location” choice is a Dynamic Choice that looks to a custom object where I have various location values stored. In my case I’ve assigned the value of the Dynamic Choice to a variable called “Location”:
And here is the “AddLocation” choice that shows the “Show Input on Selection” checkbox marked and the Label value that will show up to the left of the pop-up text field:
When the user selects the “Add Location” choice they get a little pop-up text box where they can enter text:
Finally, here is how I gained access to the value typed into the pop-up text field (in this case “Timbuktu”) to show to the user. I’ve made the default value of a variable the AddLocation choice value:
Here is a display of the screen choice field value, the choice value itself, and the value of the Location variable. You can see that the screen field and choice are returning the value of the AddLocation choice (which I’ve given a value of “Add Location”). The variable, however, is the value that was typed into the little pop-up field.
In my example I just made the default value of my variable the value of the AddLocation choice field, but of course you could also use an Assign element and assign the choice to a variable.
Now I must reiterate a little caveat. This is important, and it tripped me up for awhile.
The value of the choice is whatever the user typed, not the default stored value.
That’s worth saying again, but I’ll refrain. What that means, though, is when you want to save the user’s input to the database, just go ahead and save your screen choice field to your database without the extra assignment. You’ll only need to use the assignment if you want to show the user what they typed in!