Control a Flow’s Finish Behavior by Wrapping the Flow in a Custom Aura Component
By default, when a flow user clicks Finish, a new
interview starts and the user sees the first screen of the flow again. By embedding
a flow in a custom Aura component, you can shape what happens when the flow finishes
by using the onstatuschange action. To redirect
to another page, use one of the force:navigateTo* events such as force:navigateToObjectHome or force:navigateToUrl.
<aura:component access="global">
<aura:handler name="init" value="{!this}" action="{!c.init}" />
<lightning:flow aura:id="flowData" onstatuschange="{!c.handleStatusChange}" />
</aura:component>
// init function here
handleStatusChange : function (component, event) {
if(event.getParam("status") === "FINISHED") {
// Redirect to another page in Salesforce, or
// Redirect to a page outside of Salesforce, or
// Show a toast, or...
}
}
Example
This function redirects the user to a case created in the flow by using the force:navigateToSObject event.
handleStatusChange : function (component, event) {
if(event.getParam("status") === "FINISHED") {
var outputVariables = event.getParam("outputVariables");
var outputVar;
for(var i = 0; i < outputVariables.length; i++) {
outputVar = outputVariables[i];
if(outputVar.name === "redirect") {
var urlEvent = $A.get("e.force:navigateToSObject");
urlEvent.setParams({
"recordId": outputVar.value,
"isredirect": "true"
});
urlEvent.fire();
}
}
}
}