1

I am new the lightning.So for accessing fields in the components i am facing issueS where we access the fields using dot notation.In the below code i am not getting how to access Initiative_Organization_Unit__c.Name and Below is the code:-

OrgListController

public class OrgListController {
    @AuraEnabled
    public static List<Organization_Unit__c > getOrgUnit(Id iniId) {
        return [
            select Initiative__c,Organization_Unit__c,Organization_Unit_Name__c,Initiative_Organization_Unit__c.Name,Region__c,Region__r.name 
            from Organization_Unit__c 
            where initiative__c=:iniId
        ];
    }
}

OrgUnit.cmp

<aura:component Controller="OrgListController" implements="flexipage:availableForRecordHome,force:hasRecordId" access="global">
    <aura:attribute name="recordId" Type="id" />
    <aura:attribute name="mydata" type="Object"/>
    <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
    <aura:attribute name="orgList" type="Organization_Unit__c[]"/>
    <aura:attribute name="Columns" type="List" />

    <lightning:card iconName="standard:knowledge" title="Initiative Organization Units" class="slds-card slds-card_boundary forceRelatedListCardDesktop">
        <lightning:datatable data="{!v.mydata }" columns="{! v.Columns }" keyField="Id" hideCheckboxColumn="true"/>
    </lightning:card>
</aura:component>

OrgUnitController.js

({
    doInit : function(component, event, helper) {
        component.set("v.Columns", [
            {label:"Initiative Organization Unit Name",fieldName:"InitiativeOrganizationUnitName",type:"text"},
            {label:"Organization Unit", fieldName:"url", type:"url", typeAttributes:{label:{ fieldName:"Organization_Unit_Name__c"},target:"_blank" }},
            {label:"Region", fieldName:"Region__r.name", type:"text"}
        ]);
        helper.getData(component);
    } 
})

OrgUnithelper.js

({
    getData : function(component) {
        var action = component.get('c.getOrgUnit');
        action.setParams({
            "iniId": component.get("v.recordId")
        });
        console.log(action);
        action.setCallback(this, $A.getCallback(function(response) {
            var state = response.getState();
            console.log('state'+state);
            if(state === "SUCCESS") {
                var mydata = response.getReturnValue();
                var formattedData;
                console.log(mydata);
                if(mydata){
                    formattedData = mydata.map(function (record){
                        record.url = '/'+ record.Id;
                        console.log('record'+record);
                        return record;
                    });
                }   
                //Added for dot notation start
                for (var i = 0; i < mydata.length; i++) {
                    var row = mydata[i];
                    console.log('row value'+row);
                    if(row.Initiative_Organization_Unit__c)
                        row.InitiativeOrganizationUnitName=row.Initiative_Organization_Unit__c.Name;
                }
                component.set('v.mydata',mydata);   //Dot notation change end
                component.set('v.mydata', formattedData);
                console.log('component  set'+component);
            }
            else if(state === "ERROR") {
                var errors = response.getError();
                console.error(errors);
            }
        }));

        $A.enqueueAction(action);
    }
})

Please help me with this.

Thanks!!

5
  • See e.g. Parent Field in Lightning Datatable. Also note that a custom relationship reference ends in __r not __c. Are you sure that you want fields from a related object?
    – Keith C
    May 29 '18 at 7:09
  • yes keith i want fields from related list...but i am getting blank values from that...i dont know how to access them..... if i access using dot notation its not working
    – user46777
    May 29 '18 at 7:55
  • Follow the link I posted. You have to "flatten" the data values yourself.
    – Keith C
    May 29 '18 at 8:44
  • hi keith,i have made the changes following your link but still i am not able to access dot notation value,can you please check in the above code i have edited the code ...thanks
    – user46777
    May 29 '18 at 8:53
  • I'll leave that to someone else...
    – Keith C
    May 29 '18 at 10:08

Your Answer

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

Browse other questions tagged or ask your own question.