0

I have embedded a screen flow in an Aura component and I want to control the flow's Finish behaviour to redirect to a URL after clicking on Finish.

Aura component:

 <aura:component implements="flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,force:lightningQuickActionWithoutHeader,lightning:availableForFlowActions" access="global" >
    
    <aura:handler name="init" value="{!this}" action="{!c.init}" />
    <lightning:flow aura:id="flowData" onstatuschange="{!c.handleStatusChange}"/>
    </aura:component>

Controller:

({
init : function (component) {
    
// Find the component whose aura:id is “flowData”
var flow = component.find("flowData");
// In that component, start your flow. Reference the flow’s Unique Name.
flow.startFlow("HRCFSL_Create_Work_Order_SF");
},
    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 === "varWorkOrderId") {
            var urlEvent = $A.get("e.force:navigateToUrl");
            urlEvent.setParams({
                "url": "com.salesforce.fieldservice://v1/sObject/" + varWorkOrderId.value,
                "isredirect":"true"           
            });
            urlEvent.fire();
         }
      }
   }
}

})

When running the flow in the Salesforce Mobile app, I get the error Cannot read property 'setParams' of undefined. Can anyone tell what I'm doing wrong?

1

It's e.force:navigateToURL, not e.force:navigateToUrl. Make sure you pay attention carefully in JavaScript, as it is cAsE-sEnSiTiVe. If you ever see this, it's because $A.get didn't return an object, which is why the variable was undefined/null.

1
  • Thank you sfdcfox! That resolved the problem! – Pietro Apr 10 at 11:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.