1

Im using an aura component as an action button to display a flow on lightning experience. At the end of the flow I need to redirect the user to the new record created in the flow.

COMPONENT

<aura:component implements="force:lightningQuickAction,force:hasRecordId"
                controller="SpinOffController">
    <aura:attribute name="isOpen" type="Boolean" default="false" access="private"/>
    <aura:handler name="init" value="{!this}" action="{!c.init}"/>
    <lightning:flow aura:id="flowData" onstatuschange="{!c.closeModalOnFinish}"/>
</aura:component>

CONTROLLER: closeModalOnFinish function

closeModalOnFinish : function (component, event) {
       console.log(event.getParam("status"));
       if(event.getParam("status") === "FINISHED") {
          var outputVariables = event.getParam("outputVariables");
          console.log(outputVariables);
          outputVariables.foreach( function(outputVar){
               if(outputVar.name === 'newSpinoffId'){
                   var urlEvent = $A.get("e.force:navigateToSObject");
                   urlEvent.setParams({
                       //"recordId": "a0J050000005TTkEAM",
                       "recordId": outputVar.value,
                       "isredirect": "true"
                   });
                   urlEvent.fire();
               }
          });
       }
    }

I have a console.log on line 5 to track the return value of the method "event.getParam()", it always return undefined. HEEELP PLEASE! D:

Variable setup enter image description here

enter image description here

1
  • Did my solution work for you? Mar 15, 2021 at 21:05

1 Answer 1

0

EDIT: I think my answer was not much good, so I recreated and got it working.

Things to check:

  • Make sure your output variables are enabled for input AND output.
  • Ensure the flow is either a screen or autolaunched flow.
  • Check your javascript. I noticed that your forEach loop was not correctly capitalized. Yours was spelled foreach

Here is my test code:

<aura:component implements="force:lightningQuickAction,force:hasRecordId">
    <aura:attribute name="isOpen" type="Boolean" default="false" access="private"/>
    <aura:attribute name="testVal" type="String" />
    <aura:handler name="init" value="{!this}" action="{!c.init}"/>
    <lightning:flow aura:id="flowData" onstatuschange="{!c.closeModalOnFinish}"/>
</aura:component>

init: function (component) {
  var flow = component.find("flowData");
  flow.startFlow("testFlow");
},
closeModalOnFinish: function (component, event) {
  if (event.getParam("status") === "FINISHED") {
    var outputVariables = event.getParam("outputVariables");
    //make sure forEach has the correct capitilization.
    outputVariables.forEach(function (outputVar) {
      if (outputVar.name === 'testVal') {
        console.log('found testVal! ' + outputVar.name);
      }
    });
  }
}

Here's the flow. It's very simple - just takes an input and assigns it to a variable. I can verify that when this is launched, it takes the variable outputs the value to the console.

flow overview

Here's where the input value is assigned to the flow variable: flow variable assignment

var outputVariables = event.getParam("outputVariables");

Has a value.

Check these things and I think this will work for you.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .