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
Abdulhannan Patel 8Abdulhannan Patel 8 

recordData not loading the info from the custom lightning action on task page

Hello,

I have one custom lightning action on the task page. I am trying to show a create event page with some events fields prepopulated like WhoId and WhatId from the task. I am using the force:recordData to get the data from task and pass it to the event page. However, the data is not loaded in the targetFields attribute. Can someone help me here?

<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,force:hasRecordId,force:lightningQuickAction"
                access="global" controller="ScheduleEventController" extends="c:Base" description="Create_Follow_up_Event">

    <aura:attribute name="simpleRecord" type="Object"/>
    <aura:attribute name="recordError" type="String"/>
    
    <force:recordData aura:id="recordLoader1"
                      recordId="{!v.recordId}"
                      layoutType="FULL"
                      targetFields="{!v.simpleRecord}"
                      recordUpdated="{!c.myAction}" />

    <lightning:spinner variant="brand"  size="medium" />

    <!-- Display Lightning Data Service errors, if any -->
    <aura:if isTrue="{!not(empty(v.recordError))}">
        <div class="recordError">
            <ui:message title="Response" severity="info" closable="true">
                {!v.recordError}
            </ui:message>
        </div>
    </aura:if>
</aura:component>


({
    myAction : function(component, event, helper) {
            //$A.get("e.force:closeQuickAction").fire();
            console.log('I am called');
            var taskId = component.get("v.recordId");
            var contactId = component.get("v.simpleRecord.WhoId");
            console.log('taskId>>',taskId);
            console.log('simpleRecord>>',component.get("v.simpleRecord"));
    }
})

The contactId is null in the client side controller!

Thank you guys.
Raj VakatiRaj Vakati
Is this is complete code ??


Try like below


<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,force:hasRecordId,force:lightningQuickAction"
                access="global" controller="ScheduleEventController" extends="c:Base" description="Create_Follow_up_Event">

    <aura:attribute name="simpleRecord" type="Object"/>
    <aura:attribute name="recordError" type="String"/>
    
    <force:recordData aura:id="recordLoader1"
                      recordId="{!v.recordId}"
                      layoutType="FULL"
                      targetFields="{!v.simpleRecord}"
                       fields="Id, Name"
                      recordUpdated="{!c.myAction}" />

    <lightning:spinner variant="brand"  size="medium" />

    <!-- Display Lightning Data Service errors, if any -->
    <aura:if isTrue="{!not(empty(v.recordError))}">
        <div class="recordError">
            <ui:message title="Response" severity="info" closable="true">
                {!v.recordError}
            </ui:message>
        </div>
    </aura:if>
</aura:component>
 
Abdulhannan Patel 8Abdulhannan Patel 8
Thank you for your response Raj. You are right the code is not complete however, in the current code, even if I pass the values to the field attribute of recordData, the field values are not available in the myAction method. Because, as per the documentation, the method mentioned in the afterUpdated attribute of recordData is called after the data is fetched right?

I tried putting id and whoId in the fields to fetch and console log on the myAction showed Undefined value for the simpleRecord component attribute.

Am I missing something?