0

我对 Aura Component 和 Javascript 还很陌生,所以如果您发现我的措辞不准确,我深表歉意。

在我之前的问题中,我能够知道如何获取当前的 recordID 并将其作为组件控制器中的变量传递给 Flow。我的目标是获取页面的当前 recordID,它可能是 Opportunity Account 和 Lead,甚至可以将其设置为 null,我的流程可以处理所有 ID。

这是我的代码:

零件:

    <aura:component implements="flexipage:availableForAllPageTypes,force:hasRecordId,lightning:isUrlAddressable" access="global" >
    <aura:handler name="change" value="{!v.pageReference}" action="{!c.reInit}" event="force:refreshView" />
     <aura:handler name="change" value="{!v.recordId}" action="{!c.onRecordIdChange}"/>
     <lightning:utilityBarAPI aura:id="utilitybar" />
    <br/>
      Account Id is {!v.recordId} // This updating properly everytime I switch from home screen to recordID its updating real time.
    <lightning:formattedText value="{!v.recordId}" aura:id="ThisRecord" />
    <lightning:flow aura:id="flowData" onstatuschange="{!c.minimizeUtility}" />

</aura:component>

JS 组件控制器:

   ({
   minimizeUtility : function(component, event, helper) {
        if(event.getParam("status") === "FINISHED") {
            
        var utilityAPI = component.find("utilitybar");
        utilityAPI.minimizeUtility();
        }
    },
    
    onRecordIdChange : function(component, event, helper) {
        
       $A.get("e.force:refreshView").fire();
        
        var newRecordId = component.get("v.recordId");
        console.log(newRecordId);
          // Find the component whose aura:id is "flowData"
        var flow = component.find("flowData");
      
      const recordId = component.find("ThisRecord").get("v.value"); const inputs = []; if(recordId) inputs.push({name:"recordId",type:"String",value:recordId});

        // In that component, start your flow. Reference the flow's API Name.
        flow.startFlow("MyFlowHere",
                     inputs );
        
    
        
    },
    
       reInit : function(component, event, helper) {
       alert("hello there!"); 
    },
    
   
   getInput : function(cmp, event) { 
      alert("hello there!"); 
   }
 
})

现在我已经设置了组件,它正在按预期发送当前的记录 ID,但我有一个小问题。您看看我是否在主屏幕上并切换到 v.RecordID 未更新的帐户。即使它设置为在每次 v.RecordID 更改时重新启动流程,但事实并非如此,所以当主屏幕有 v.Record = null 时,即使我跳入帐户页面,它也不会在那里更新记录 ID传递的 ID 不正确。

每次页面更改或 v.RecordID 更改以重新渲染时,我都需要一种刷新或重新启动流功能的方法,const recordId = component.find("ThisRecord").get("v.value"); 以便它始终获取更新的 ID。我可以看到每次切换记录时都会更新 aura 组件文本,但获取 ID 的功能不会在那里刷新,因为总是有旧的 ID。

我试图更改我的组织上的会话设置,但这并没有帮助我在这里阅读它, 但这并没有帮助。

如果您知道任何帮助我的方法,请告诉我!谢谢!

4

1 回答 1

0

好的,我想通了!

我发布这个是为了帮助任何需要更简单解决方案的人。我看到了一些类似的问题,答案很长而且不清楚。

为了在刷新时拥有最新的 RecordId,您将需要重新启动流程,但没有默认的方式来执行此操作,因此我有一个处理程序可以在记录更改时触发操作。它只是简单地销毁了旧的 Flow 组件并从头开始动态创建一个并再次调用该流。

零件:

<aura:component implements="flexipage:availableForAllPageTypes,force:hasRecordId" access="global" >
<aura:handler name="change" value="{!v.recordId}" action="{!c.onRecordIdChange}"/> // This will fire function OnRecordIdChange
  Account Id is {!v.recordId}  . 
<lightning:flow aura:id="flowData" />
      {!v.body}
</aura:component>

控制器 JS:

  ({
 
    onRecordIdChange : function(component, event, helper) {
           
   // We are going to destroy our Flow Element and dynamically re-create it every time the recordID changes. It goes it checks if there is a flow with same name, Destroy it and dynamically re-create it, once you are re-calling the flow it will take the updated ID's
        
               var flowfinal = component.find("flowData");

        if ($A.util.isUndefinedOrNull(flowfinal)) {
           
        }
        else
        {
             flowfinal.destroy();
        }
        $A.createComponent(
            "lightning:flow",
            {
                "aura:id": "flowData"
            },
            function(NewFlow, status, errorMessage){
                //Add the new button to the body array
                if (status === "SUCCESS") {
                    var body = component.get("v.body");
                    body.push(NewFlow);
                    component.set("v.body", body);
                     console.log(NewFlow)
                }
                else if (status === "INCOMPLETE") {
                    console.log("No response from server or client is offline.")
                    // Show offline error
                }
                else if (status === "ERROR") {
                    console.log("Error: " + errorMessage);
                    // Show error message
                }
            }
        );
        
        
        
          // Find the component whose aura:id is "flowData"
        var flow = component.find("flowData");
      
     var recordId = component.get("v.recordId");
        const inputs = [];
        console.log(recordId);
        if(recordId) inputs.push({name:"recordId",type:"String",value:recordId});
        console.log("In puts here");
         console.log(recordId);
        // In that component, start your flow. Reference the flow's API Name.
        flow.startFlow("One_Click_Request_Flow_1",
                     inputs );
        
    
        
    }
  
 
})
于 2021-11-30T20:03:47.130 回答