0

I have been trying to dynamically assign variable names to Lightning Page Variable.

My Lightning Component has the following variable:

<aura:attribute name="applicationOptions" type="List" default="[]"/>

My Controller has the following method:

helper.retrieveFieldOptions(component, event, helper,component.get("v.appField"),component.get("v.applicationOptions"));

My helper is trying to dynamically get the picklist values for each field from Dynamic Objects via apex:

retrieveFieldOptions: function(component,event,helper,fieldName,lstVar){
var action = component.get("c.getselectOptions");  
    action.setParams({
           objObject : "Case", 
           fld : fieldName
            }); 
     action.setCallback(this, function(response) {
        var state = response.getState();
        if (state === "SUCCESS"){
            var result = response.getReturnValue();
            var retrievedPickListVal = [];
            for (var i = 0; i < result.length; i++) {
                retrievedPickListVal.push({
                    label: result[i],
                    value: result[i]
                });
            }
            component.set(lstVar, retrievedPickListVal);
         }
    });
    $A.enqueueAction(action);
},

In the end, am trying to assign the result back to the List Variable which seems to be not working. Is this even possible to use component.set dynamically?

I have around 20 such picklist fields and I don't want to create a separate method for each one.

Any help is much appreciated!

1 Answer 1

0

component.set() takes a string as the first parameter. You are passing the attribute instead. Change your controller to

helper.retrieveFieldOptions(component, event, helper,component.get("v.appField"),"v.applicationOptions")
1
  • Worked like a charm. Thank you!
    – user102266
    Aug 4, 2021 at 0:40

You must log in to answer this question.

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