Sub topic 6
Adding the component to a screen and using its outputs
This chapter assumes you can deploy an LWC with @api properties and that you know Flow Builder basics: screen flows, variables, and screen elements. It also assumes you have a component with a lightning__FlowScreen target, such as the quantityPicker from the earlier chapters.
Place the component on a screen
After you deploy the bundle, Flow Builder lists it under the Custom section of the Screen element's component palette. The list uses the masterLabel from the meta.xml file. If the component is missing, check three things:
isExposedistrue.lightning__FlowScreenappears intargets.- The deployment succeeded in the org you are using.
To place the component:
- Open or create a screen flow and add a Screen element.
- Drag Quantity Picker from the palette onto the canvas.
- Select the component. The properties panel shows one field for each
<property>intargetConfig.
Set the inputs
Each property with an input role appears as a field. You can fill it in one of three ways:
- Type a literal value, such as
Quantityforlabel. - Reference a resource, such as
{!var_DefaultQuantity}. - Leave it empty, so the component receives
undefinedand falls back to its own default.
A property with role="outputOnly" does not accept a value from the flow. It only returns one. A property with no role works in both directions.
Store the outputs in a variable
Flow Builder exposes outputs through the component's API name. The default name is cmpQuantityPicker. You can rename it in the properties panel, and you should, because later elements reference it.
An output is available only after the user leaves the screen. When the user clicks Next, Flow Builder reads the values the component sent with FlowAttributeChangeEvent and stores them. You can then use them in the following ways:
| Where | Reference | Typical use |
|---|---|---|
| Decision element | `{!QtyPicker.quantity}` | Branch on the value |
| Assignment element | `{!QtyPicker.quantity}` | Copy it into a variable |
| Record-create or update | `{!QtyPicker.quantity}` | Write it to a field |
| Later screen | `{!QtyPicker.quantity}` | Show it in display text |
In the first column, QtyPicker is the API name you gave the component. The quantity part is the property name from meta.xml.
You can also reference the output on the same screen. Flow Builder re-evaluates screen references when a component dispatches FlowAttributeChangeEvent. A display text component can show {!QtyPicker.quantity} and update as the user types.
Check the wiring with a worked example
Suppose the flow must ask for a quantity and route large orders to a manager. Build it like this:
- Create a number variable
var_DefaultQuantitywith the default value1. - Add the Screen element and place
quantityPickeron it. - Set
labeltoOrder quantityandquantityto{!var_DefaultQuantity}. - Rename the component API name to
QtyPicker. - After the screen, add a Decision element with the outcome
Large orderand the condition{!QtyPicker.quantity}Greater Than100.
Common mistakes
- No output reaches the flow. The component changed
this.quantitybut never dispatchedFlowAttributeChangeEvent. Setting an@apiproperty inside the component does not update the flow. - The component does not appear. Flow Builder caches the palette. Reload the page after deploying.
- The old property list still shows. Changing a property's
typein meta.xml can break existing flows that use it. Test those flows after you deploy a change. - The output is empty after Next. Check that the property name in the event matches the meta.xml name exactly, including case.
Exercise
A user types 5 in your component and clicks Next, but a Decision element reading {!QtyPicker.quantity} always sees an empty value. The component sets this.quantity in its change handler. What is the most likely cause, and how do you fix it?
Show answer
The component updates its own property but never tells the flow. Add this.dispatchEvent(new FlowAttributeChangeEvent('quantity', this.quantity)); to the handler, and confirm that quantity is declared in meta.xml without role="inputOnly".
Exercise
Which role would you give a property that the component calculates and the flow only reads?
Show answer
role="outputOnly". Flow Builder then shows it only as an output and does not let the flow set it.