0

How can I pass the record Id to lightning flow component. I already add a variable in flow with name recordId and I add the aura attribute with name recordId, but it doesn't work.

COMPONENT

<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
    <aura:attribute name="recordId" type="String"/>
    <aura:attribute name="isOpen" type="Boolean" default="false" access="private"/>
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>   
    <aura:if isTrue="{!v.isOpen}">    
        <div style="height: 500px;">
            <section role="dialog" tabindex="-1" class="slds-modal slds-fade-in-open">
                <div class="slds-modal__container">
                    <header class="slds-modal__header slds-modal__header_empty">
                        <lightning:buttonIcon iconName="utility:close" class="slds-modal__close" onclick="{!c.closeFlowModal}"/>
                    </header>
                    <div class="slds-modal__content slds-p-around_medium">
                        <lightning:flow aura:id="flowOutput" onstatuschange="{!c.closeModalOnFinish}" />
                    </div>
                </div>
            </section>
            <div class="slds-backdrop slds-backdrop_open"></div>
        </div> 
    </aura:if>
</aura:component>

CONTROLLER

({
doInit : function(component, event, helper) {
       component.set("v.isOpen", true);    
       var flow = component.find("flowOutput");
       flow.startFlow("create_task");
    },

closeFlowModal : function(component, event, helper) {
        component.set("v.isOpen", false);
    },

closeModalOnFinish : function(component, event, helper) {
        if(event.getParam("status") === "FINISHED") {
            component.set("v.isOpen", false);
        }
    }
})

1 Answer 1

1

We can pass the input parameters to the flow from lightning aura component in js file as below.

({
doInit : function(component, event, helper) {
       component.set("v.isOpen", true);    
       var flow = component.find("flowOutput");
// Added the below piece of code to pass the input parameters
    var inputVariables = [
            {
                name : "Accountid",
                type : "String",
                value : component.get("v.recordId")
            }
        ];
       flow.startFlow("create_task",inputVariables);
    },

closeFlowModal : function(component, event, helper) {
        component.set("v.isOpen", false);
    },

closeModalOnFinish : function(component, event, helper) {
        if(event.getParam("status") === "FINISHED") {
            component.set("v.isOpen", false);
        }
    }
})

( In my dev org I created lightning aura component which invokes when we click on "create task" button on account object and when user on clicks the "create task" button it will create the task linking the associated account through flow)

Reference documentation (https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/components_using_flow_inputs_set.htm) shows us how to pass the parameters from the component to Flow.

You must log in to answer this question.

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