1

Im new here. I'm working on modifying a Lightning Web Component (LWC) that is used within a Salesforce Flow screen. I've added a checkbox input to the LWC, and my goal is to pass the value of that checkbox (true or false) to a Flow variable.

I've set up the checkbox in the LWC and exposed its value using a public @api property. However, when I run the Flow in debug mode, the Flow variable that should receive the checkbox value is always null, no matter if the checkbox is checked or unchecked by the user.

How can I ensure the checkbox value is properly passed from the LWC to the Flow variable during execution? I'm looking for guidance on what I might be missing — whether it's in the LWC code, the metadata config, or how the Flow variable binding is set up. HTML

<lightning-input type="checkbox" label="PO number is required" checked={isPoRequired} onchange={handlePoRequiredChange}></lightning-input>

JS

@api isPoRequired;
isPoRequired = true;
    handlePoRequiredChange(event){
        this.isPoRequired = event.target.checked;
    }

XML

<property name= "isPoRequired" label="PO is required checkbox" type="Boolean" />
3
  • 1
    Hi and welcome to SFSE. Please take a minute to read How to Ask and perhaps take the tour before you edit your question to show clearly what the problem is. I am assuming the problem is due to trying to write to the API property. You need to make these getter/setter based, setting the underlying private value, as they are otherwise immutable to the LWC itself. You will also want to first a flow attribute change event when the value changes. Commented May 3 at 17:33
  • assuming you have set the XML properly, you should be able to get the output from the LWC in screen flow, which you can then assign to a flow variable. You do this within the flow. Commented May 4 at 13:35
  • I put the variable into the input instead of output in the flow. Lol appreciate the inputs. Commented May 10 at 16:13

1 Answer 1

0

You need to publish the value to the flow itself. With the code you have, the flow has no way to know about any change.

You need to use the FlowAttributeChangeEvent from lightning/flowSupport.

ie.

Add

import { FlowAttributeChangeEvent } from 'lightning/flowSupport';

to the top of your js file.

then within your handlePoRequiredChange method call the event.

handlePoRequiredChange(event){
    this.isPoRequired = event.target.checked;
    this.dispatchEvent(new FlowAttributeChangeEvent('isPoRequired ', this.isPoRequired));
}

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.