What is the correct way to “set the attribute” per flow documentation

The flow documentation is littered with this ‘tip’ but has no examples of what specifically to do. (bold is mine, for emphasis)

By default, screen components that require Lightning runtime have no memory. If a user enters a value, navigates to another screen, and returns to the component’s screen, the user-entered value is lost. To enable a flow to remember the value of an attribute, set the attribute. The flow stores the value automatically. If you store values manually, store the attribute’s output value in a variable.

Can someone explain exactly what the right way to ‘set the attribute’ is? I have pulled this off in various ways that seem to work, and curious if there is some learning here as to the best way to do this. The sentence afterwards further compounds my confusion by stating that ‘the flow stores the values automatically’ – so does this mean we no longer need to do anything and its all magically fixed?

A few selected instances of this tip (pretty much all component documentation)
address component
toggle

Answer

I agree that how it works is a bit confusing. I’ve done a bit of testing and I think this is how it works. However I have only tested this with the address input field, so please be aware that other elements may behave differently.

When you switch between screens all the element values are discarded. You effectively return to the screen as it was when you first loaded it. Sometimes this is desired behavior because it forces the user to reconsider everything on the screen. At other times it’s annoying. (Let’s say you’ve input an address and made a typo. You click back and the whole address is gone.)

When you want to remember the values, there are two situations that may be relevant.

1) You only want to use the values of the elements only within that specific flow screen.
You use them for instance to toggle the visibility of other parts of the screen. If you still want the flow screen to remember the input value, then you need to set an input attribute for that screen element. Just the act of setting a value there is enough to make sure the flow will remember the user input when they click back. This solution requires that you deselect the manual variable assignment checkbox. I just tested this with an address element and what you put in doesn’t seem to matter. It can be a variable (it won’t be changed by the screen element). It can be a normal text string. Or it can even be a space or a {!$GlobalConstant.EmptyString}.

2) Often you will want to use the user input in other elements of your flow. In that case you will need to use the manual variable assignment option. However, if you still want the flow to remember the values if you click back, then just setting the manual variable assignment is not enough. You stil need to set the input attributes.

However, and this is odd, it doesn’t seem to matter much what you put there. I have used three {!$GlobalConstant.EmptyString} in the input attributes, and put the three address fields in the same output variable and when I clicked back it had still remembered the proper values of each field. Of course one shouldn’t do that in a real flow.

Attribution
Source : Link , Question Author : gorav , Answer Author : Kasper

Leave a Comment