Available For Flow Actions
lightning:availableForFlowActions
Enables a component's controller to be used as an action in a flow.
For Use In
Lightning Experience
Add the lightning:availableForFlowActions interface to a Lightning component to make it available as a flow action. When a component is executed as a flow action, the flow calls the invoke method in the client-side controller. Flows that include Lightning components are supported only in Lightning runtime.
Lightning components that implement lightning:availableForFlowActions are available as Local Action elements in the Cloud Flow Designer. If an attribute is declared in the component's design resource, flow admins can pass values between that attribute and the flow when they configure the Local Action element.
To run your code asynchronously, for example because you're making an XML HTTP request (XHR), return a Promise.
When the method finishes or the Promise is settled, control is returned back to the flow.
-
Asynchronous Code: When a Promise is fulfilled, the next element in the flow is executed. When a Promise is rejected or times out, the flow takes the Local Action element's fault connector and sets
$Flow.FaultMessageto the error message. By default, the error message is "An error occurred when the flow tried to execute the ccomponent.". To customize the error message, return it as an error in the reject()call. When a Promise times out, it returns control to the flow, but it doesn't cancel the original request. For example, if the request fires aforce:showToastevent after a delay, the event still fires even after the promise times out. To abort a Promise, use thecancelTokenattribute provided by the interface. -
Synchronous Code: When the method finishes, the next element in the flow is executed.
This example shows the markup required to add the lightning:availableForFlowActions interface to a Lightning component.
Here's an example of an asynchronous client-side controller. The invoke method returns a Promise. When the method has done all it needs to do, it completes the call. If the request is successful, the method uses resolve() to execute the next element in the flow after this action. Otherwise, it uses reject() to take the Local Action element's fault connector and sets $Flow.FaultMessage to "My error message". If the request takes too long, it uses cancelToken.promise.then to abort the request.
Here's an example of a synchronous client-side controller. When the invoke method finishes, control returns to the flow.
For more information, see Create Flow Actions By Using Lightning Components.
This interface requires your component to implement the following method.
invoke(component, event, helper): Called when a flow executes the component as a local action. To handle asynchronous calls, construct a Promise in this method.
cancelToken(Object): A token that you can use to gracefully abort a Promise. When the Promise times out,cancelToken.requestedis set totrueandcancelToken.promiseis resolved with a timeout Error object.
