3

I have the following code blocks, the populatepicklists.setCallback() seems to not be firing off. Any thoughts

Server side controller

        @AuraEnabled
    public static List<String> getActivities(){
        List<String> options = new List<String>();
        Schema.DescribeFieldResult fieldResult = Case.Activity__c.getDescribe();
        List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
        for (Schema.PicklistEntry f: ple) {
            options.add(f.getLabel());
        }
        return options;
    }

doInit Function

doInit: function(component, event, helper) {

    // Create the action
    var action = component.get("c.getCases");

    // Add callback behavior for when response is received
    action.setCallback(this, function(response) {
        var state = response.getState();
        if (component.isValid() && state === "SUCCESS") {
            component.set("v.cases", response.getReturnValue());
        }
        else {
            console.log("Failed with state: " + state);
        }
    });   

    var populatepicklists = component.get("c.getActivities");
    var inputsel = component.find("activity");
    var options = [];     

    populatepicklists.setCallback(this, function(a) {
        for(var i=0;i< a.getReturnValue().length;i++){
            options.push({"class": "optionClass", label: a.getReturnValue()[i], value: a.getReturnValue()[i]});
        }
        inputsel.set("v.options", options);

    });

    // Send action off to be executed
    $A.enqueueAction(action);

}

Component code

<aura:attribute name="options" type="String[]"/>

<ui:inputSelect aura:id="activity" label="Activity"
                    class="slds-input"
                    labelClass="slds-form-element__label"
                    value="{!v.newCase.Activity}"
                    required="true">
        </ui:inputSelect>

1 Answer 1

3

I believe you're missing a line of code:

$A.enqueueAction(populatepicklists);

Which presumably goes near the other enqueueAction call you have in doInit.

1
  • @Alex It's an easy mistake to make; I'm still just starting Lightning myself. It's a whole new beast to work with.
    – sfdcfox
    Commented Oct 13, 2016 at 17:44

You must log in to answer this question.

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