I want to take the field value dynamically in lightning controller . I got the object result but unable to the field value.

doInit: function(component, event, helper) {

    var action = component.get("c.getFieldValues");
        sObjectName :component.get("v.sObjectName"),
        fieldNames  :component.get("v.fieldNames")

    action.setCallback(this, function(response) {

        var state = response.getState();            
        var fieldArray = [];
        fieldArray = component.get("v.fieldNames").split(',');
        var accFieldName=fieldArray[0];

        if (state === "SUCCESS") {
            var objData = response.getReturnValue();
            console.log('####gotFieldValue'+objData.Name); // this line value is getting values
            console.log('####NoValue'+objData.accFieldName); //this line value is not getting 


Here for objData I am getting the value. If i try to take (objData.Name) the account name is coming .But i want to pass the field value dynamically from fieldNames.It is not working .

Please help me !!

  • do you want to get field values dynamically from list of fields? – rahul gawale Apr 26 '19 at 6:29
  • 1
    yes,I want to get the fields dynamically – jessy Apr 26 '19 at 6:51

In JavaScript, to dynamically get field of object you should use obj[FIELD].

Try this line instead:


Please mark it as solution once it works.

| improve this answer | |

If you want to get all fields, try this.

//read key
for (var key in objData) {
| improve this answer | |

We can get the field value like below :

| improve this answer | |
  • No idea why you respond to yourself instead of marking the current answer for who actually helped you – Derminal Apr 26 '19 at 20:26

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.