3

Scenario:

We have a multi-step flow made up from a number of lightning components, our first step contains a lightning:recordEditForm which creates and inserts a record and then passes the ID into a variable in the flow for use in later steps.

Issue:

When navigating back to the first step the recordID variable seams to be cleared and so the record is not getting loaded into the lightning:recordEditForm breaking our flow.

Question:

Should this variable exist for the duration of the flow even when navigating back, if not is there an alternate approach to store the created record in order to maintain our flow?


Flow with two lightning components. Flow with two components. Component 1 - Inputs Component 1 - Inputs Component 1 - Outputs Component 1 - Outputs


Component 1:

<lightning:recordEditForm objectApiName="Account" recordId="{!v.recordId}" onsuccess="{!c.handleNavigation}">
        <!-- the messages component is for error messages -->
        <lightning:messages />

        <lightning:inputField fieldName="Name" />

        <div class="slds-m-top_medium">
            <lightning:button variant="brand" type="submit" name="save" label="Save" />

    </div>
    </lightning:recordEditForm>

Controller:

({
handleNavigation : function(component, event, helper) {
    var params = event.getParams();
    component.set('v.recordId', params.response.id);
    console.log(params.response.id);
    var navigate = component.get("v.navigateFlow");
    navigate('NEXT');
}

})

Component - 2

<aura:component implements="force:lightningQuickAction,force:hasRecordId,force:appHostable,lightning:actionOverride,lightning:availableForFlowScreens,force:hasSObjectName">
<lightning:recordEditForm recordId="{!v.recordId}" objectApiName="Account" onsuccess="{!c.handleNavigation}">
        <!-- the messages component is for error messages -->
        <lightning:messages />

        <lightning:inputField fieldName="Name" />

        <div class="slds-m-top_medium">
            <lightning:button variant="brand" type="submit" name="save" label="Save" />
            <lightning:button variant="brand" name="back" label="Back" onclick="{!c.goback}"/>
        </div>
</lightning:recordEditForm>

Controller

({
handleNavigation : function(component, event, helper) {
    var navigate = component.get("v.navigateFlow");
    navigate('NEXT');
},
goback : function(component, event, helper) {
    var navigate = component.get("v.navigateFlow");
    navigate('BACK');
}

})

Wrapper component which flow where "New" action for "Account" is overriden:

<aura:component implements="force:hasRecordId,force:lightningQuickAction,lightning:actionOverride">

<aura:handler name="init" value="{!this}" action="{!c.init}"/>

<lightning:card title="New Account">
    <lightning:flow aura:id="flow" onstatuschange="{!c.handleStatusChange}"/>
</lightning:card>

Controller:

({
init : function (component) {
    var flow = component.find("flow");
    flow.startFlow("AccountCreateFlow", []);
},

handleStatusChange : function (component, event) {
    // Get the output variables and iterate over them
    var outputVariables = event.getParam("outputVariables");
    var outputVar;

    for(var i = 0; i < outputVariables.length; i++) {
        outputVar = outputVariables[i];
        if(! $A.util.isEmpty(outputVar.value)) {
            component.set("v.recordId", outputVar.value);
        } 
    }

} })

2
  • You may want to share your flows and the lightning component to help us understand better . If the recordId is passed to the flow you can get back the values from the flow back to the lightning components . Feb 6, 2018 at 16:48
  • @MohithShrivastava just updated the question with more info. Record Id is passed into the flow as a variable. Edit form on the second page is working fine by using the record Id. But when I navigate back, record Id is getting cleared and edit form cannot load the same record.
    – Ranga
    Feb 6, 2018 at 17:22

1 Answer 1

-1

Looks like you are trying to retrieve the recordId from flow's outputVariables but I think you also need to set the recordId in order to retrieve it.

Try setting recordId inside your handleNavigation like so:

    var flow = component.find("flowData");
    var inputVariables = [ { name : "recordId", type : "String", value:  params.response.id } ];
    flow.startFlow("myFlow", inputVariables);        

For details see setting flow variables.

3
  • @dev-e-loper handleNavigation method is on "Component-1" which doesn't have a flow embedded in it. So the component.find("flowData") cannot work.
    – Ranga
    Feb 7, 2018 at 9:33
  • @Ranga You could fire an event that contains recordId from Component-1. Component-2 will handle that event, retrieve and store that recordId either in the flow or it's own attribute. Feb 7, 2018 at 18:38
  • @dev-e-loper to clarify, I'm able to pass record Id from component-1 to component-2 using a flow variable and works fine. Issue happens when going back to the component-1 from component-2. At that point the recordId is getting set to null.
    – Ranga
    Feb 8, 2018 at 13:47

You must log in to answer this question.

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