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");  
           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++) {
                    label: result[i],
                    value: result[i]
            component.set(lstVar, retrievedPickListVal);

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


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")
  • Worked like a charm. Thank you!
    – user102266
    Commented 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 .