function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
GMASJGMASJ 

Lightning component wont work for very first click

Hi, 
  
   Below lightning component is working as expected only problem I see in this is when component is called from button for very first time i see both the message are populating same time. normally it must display the message only based on the condition is met. 

"Oracle ERP disti ID" is not set for this account. Please contact system administrator for more information."

 AND

"PO Tracker is lunched in New window!"
 
<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId,force:lightningQuickAction" access="global" controller="POTrackerExtLtn" >
	<aura:attribute name="act" type="Object"/>
	<aura:attribute name="key" type="String" access="private"/>
    
   <force:recordData aura:id="forceRecord"
                      recordId="{!v.recordId}"
                      targetFields="{!v.act}"
                      fields="Id,Name,Distributor__r.Oracle_ERP_disti_ID__c"
                      recordUpdated="{!c.handleRecordUpdated}"
                      mode="EDIT" />
    <div class="slds-box slds-theme_info">
     
   <!-- console.log("Record Id" + "{!v.recordId}");  
   console.log("Object " + "{!v.act}"); 
   console.log("ERP ID " + "{!v.act.Distributor__r.Oracle_ERP_disti_ID__c}");  -->
   
    <aura:if isTrue="{!v.act.Distributor__r.Oracle_ERP_disti_ID__c == null}">
	<p>"Oracle ERP disti ID" is not set for this account. Please contact system administrator for more information. </p>
    <aura:set attribute="else">
        <p>PO Tracker is lunched in New window!</p>
    </aura:set>
    </aura:if>
        
    </div>
	<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    
</aura:component>
 
({
	doInit : function(component, event, helper) {

        console.log("doInit == Start " );
        var action = component.get("c.getAccessKey");
        action.setParams({
            recordId: component.get("v.recordId")
        });
        action.setCallback(this, function(data) {
            console.log('Return Value _____________' + data.getReturnValue());
            component.set("v.key", data.getReturnValue());
            
             console.log("handleRecordUpdated == Start " );

		var urlEvent = $A.get("e.force:navigateToURL");
        console.log(component.get("v.key") );
            var url = 'https://apptest.sudhir.com/potracker/login?moduleName=trackingService&accessKey=' +  data.getReturnValue();
  
        console.log(url);
        urlEvent.setParams({
            "url": url
        });
        var erpId = component.get("v.act.Distributor__r.Oracle_ERP_disti_ID__c") + 'PPP';
        console.log(erpId + '___erpd_id ' + ( erpId  != 'nullPPP'));
        if(erpId != 'nullPPP') {
	        urlEvent.fire();
        }
        console.log("doInit == innnEnd");
            
        });
        $A.enqueueAction(action);
                
        console.log("doInit == End");
    },
    handleRecordUpdated: function(component, event, helper) {
        console.log("handleRecordUpdated == Start " );
        var eventParams = event.getParams();
         console.log("eventParams.type == " + eventParams.changeType);
        if(eventParams.changeType === "LOADED") {
           // record is loaded (render other component which needs record data value)
            console.log("Record is loaded successfully. == " + eventParams.changeType);
            console.log("doInit == innnnnStart " );

		var urlEvent = $A.get("e.force:navigateToURL");
        console.log(component.get("v.key") );
        var url = 'https://apptest.sudhir.com/potracker/login?moduleName=trackingService&accessKey=' + component.get("v.key");

        console.log(url);
        urlEvent.setParams({
            "url": url
        });
        //urlEvent.fire();
        console.log("doInit == innnEnd");
            
        } else if(eventParams.changeType === "CHANGED") {
            // record is changed
        } else if(eventParams.changeType === "REMOVED") {
            // record is deleted
        } else if(eventParams.changeType === "ERROR") {
            // there’s an error while loading, saving, or deleting the record
        }
        console.log("handleRecordUpdated == End");
    }		
})
Please suggest me how to fix this issue. 

Thanks
Sam
 
Naveen KNNaveen KN
Hi Sam, 

Try this
<aura:if isTrue="{!empty(v.act.Distributor__r.Oracle_ERP_disti_ID__c)}">
        <p>"Oracle ERP disti ID" is not set for this account. Please contact system administrator for more information. </p>
        <aura:set attribute="else">
            <p>PO Tracker is lunched in New window!</p>
        </aura:set>
    </aura:if>

Regards,
Naveen