1

I have a lwc which is used in a flow.

I have several variables from the lwc that are exposed to the flow. I need to make the flow know when these variables changes, so according to documentation I need to use FlowAttributeChangeEvent.

Say my code looks something like this:

@api apiOne
@api apiTwo
@api apiThree
buttonclick(event) {
//something happens

    const variable1 = new FlowAttributeChangeEvent('apiOne' , this.apiOne);
    this.dispatchEvent(variable1);
}

My questions is, how do I do something similar to the remaining attributes, apiTwo, apiThree etc? Supposing I do not wish to create several FlowAttributeChangeEvent. Is it possible to accommodate all these attributes to the same FlowAttributeChangeEvent? I read somewhere that this was not possible and I have been trying myself, but without any luck. Cheers.

2

Yes, you need multiple events, but you can do this programmatically if you wanted to:

["apiOne", "apiTwo", "apiThree"].forEach((prop) =>
  this.dispatchEvent(new FlowAttributeChangeEvent(prop, this[prop]))
);

Or, you could set an attribute on an input element, etc. The main advantage of JavaScript is is can be dynamic, so you don't necessarily need to have each attribute in a different method.

4
  • thanks a lot for the reply. So does that mean i would have to say something like: const attributeChange1 = new FlowAttributeChangeEvent('apiOne' , this.apiOne); this.dispatchEvent(variable1); const attributeChange2 = new FlowAttributeChangeEvent('apiTwo' , this.apiTwo); this.dispatchEvent(attributeChange2); and so on or something similar to what you suggested? How come this cant be created just using a single event? – AndersenAnd Jun 1 '20 at 18:56
  • @AndersenAnd No, you can't use a single event, but you also don't need to write all that code. I demonstrated how you can dispatch multiple events using just a couple of lines of code. – sfdcfox Jun 1 '20 at 19:03
  • hi again sfdcfox, my comment was meant for why its not possible, since its possible to pass multiple parameters to custom events. I appreciate your answer, it was very helpful, thanks a lot. I have voted it as best answer and I will try what you have mentioned. – AndersenAnd Jun 1 '20 at 19:24
  • 2
    @AndersenAnd for custom events, sure, but this is a standard event that has a standard signature. You can't alter its behavior. – sfdcfox Jun 1 '20 at 20:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.