I am using the Lightning Data service in my Lightning Component to update a case record, before I do update the record I need to check on the field value and update accordingly. Below is my component

<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId" access="global"  >
<aura:attribute name="loaded" type="Boolean" default="false" />
<lightning:spinner variant="brand" alternativeText="Loading..." class="{!(v.loaded? 'slds-show': 'slds-hide')}" />
 <lightning:recordEditForm aura:id="form" 
        <lightning:inputField aura:id="statusInput" fieldName="Status" class="slds-hide" />
        <lightning:button variant="brand" type="submit" label="Transfer" />

and the controller is like

    handleSubmit: function(component, event, helper) {
    var fields = event.getParam('fields');
    var country = fields.Account_Country__c;
    if( country == 'XYZ')
        fields.OwnerId = 'XXXXXXXXXX'; 
        fields.OwnerId = 'YYYYYYYYYYY'; 

Here the country field is always undefined in the controller I tried even changing the to like below

   var country = component.get("v.recordId").Account_Country__c;

Even this is not returning the field value associated with the case record.How can I reterieve the field value so I can use them in the controller.

enter image description here enter image description here

1 Answer 1


Its because you are missing the lightning:inputField for Account_Country__c

<lightning:inputField aura:id="accountCountryInput" fieldName="Account_Country__c" class="slds-hide" />

And you can access it like

var fields = event.getParam('fields');
var country = fields.Account_Country__c;

Also, the below code will never work as it a recordId, not the record itself.

var country = component.get("v.recordId").Account_Country__c;
  • I did try that even still I see undefined. Can you Please look in to the screenshot I added now
    – user81642
    Oct 1, 2020 at 15:19
  • @user81642 you are still trying to access it using component.get("v.recordId"), which will never work. Try to access it using fields.Account_Country__c. See the update. Oct 1, 2020 at 15:23
  • I do have that var country = fields.Account_Country__c; still undfined
    – user81642
    Oct 1, 2020 at 15:30
  • added screenshot again
    – user81642
    Oct 1, 2020 at 15:36
  • @user81642 please check if the user has sufficient access to the field and check if the field api name is correct. remember the API name is case sensitive Oct 1, 2020 at 16:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .