Newer Version Available
Set Flow Input Variable Values from a Wrapper Aura Component
For each variable you set, provide the variable's name, type, and value. For type, use the API name for the flow data type. For example, for a record variable use SObject, and for a text variable use String.
1{
2 name : "varName",
3 type : "flowDataType",
4 value : valueToSet
5},
6{
7 name : "varName",
8 type : "flowDataType",
9 value : [ value1, value2]
10}, ...Example
This JavaScript controller sets values for a number variable, a date collection variable, and a couple of record variables. The Record data type in Flow Builder corresponds to SObject here.
1({
2 init : function (component) {
3 // Find the component whose aura:id is "flowData"
4 var flow = component.find("flowData");
5 var inputVariables = [
6 { name : "numVar", type : "Number", value: 30 },
7 { name : "dateColl", type : "String", value: [ "2016-10-27", "2017-08-01" ] },
8 // Sets values for fields in the account record (sObject) variable. Id uses the
9 // value of the component's accountId attribute. Rating uses a string.
10 { name : "account", type : "SObject", value: {
11 "Id" : component.get("v.accountId"),
12 "Rating" : "Warm"
13 }
14 },
15 // Set the contact record (sObject) variable to the value of the component's contact
16 // attribute. We're assuming the attribute contains the entire sObject for
17 // a contact record.
18 { name : "contact", type : "SObject", value: component.get("v.contact") }
19 },
20 ];
21 flow.startFlow("myFlow", inputVariables);
22 }
23})Example
Here's an example of a component that gets an account via an Apex controller. The Apex controller passes the data to the flow's record variable through the JavaScript controller.
1<aura:component controller="AccountController" >
2 <aura:attribute name="account" type="Account" />
3 <aura:handler name="init" value="{!this}" action="{!c.init}"/>
4 <lightning:flow aura:id="flowData"/>
5</aura:component>1public with sharing class AccountController {
2 @AuraEnabled
3 public static Account getAccount() {
4 return [SELECT Id, Name, LastModifiedDate FROM Account LIMIT 1];
5 }
6}1({
2 init : function (component) {
3 // Create action to find an account
4 var action = component.get("c.getAccount");
5
6 // Add callback behavior for when response is received
7 action.setCallback(this, function(response) {
8 if (state === "SUCCESS") {
9 // Pass the account data into the component's account attribute
10 component.set("v.account", response.getReturnValue());
11 // Find the component whose aura:id is "flowData"
12 var flow = component.find("flowData");
13 // Set the account record (sObject) variable to the value of the component's
14 // account attribute.
15 var inputVariables = [
16 {
17 name : "account",
18 type : "SObject",
19 value: component.get("v.account")
20 }
21 ];
22
23 // In the component whose aura:id is "flowData, start your flow
24 // and initialize the account record (sObject) variable. Reference the flow's
25 // API name.
26 flow.startFlow("myFlow", inputVariables);
27 }
28 else {
29 console.log("Failed to get account date.");
30 }
31 });
32
33 // Send action to be executed
34 $A.enqueueAction(action);
35 }
36})