+ Start a Discussion
VRKVRK 

Sort Order not working for Dependent picklist fields in custom lightning application

Sub : Sort order not workign for Dependent picklist fields for Product 
Hi folks,
i have 3 picklist fields : Team, product and stragy
Based on Team selection Product values will display ...
For Team picklist felds SORT function is working BUT for product picklist Field SORT is not working 
can any one pls check my code and let me know your ideas to fix this 
Comp:
        <div class="slds-col slds-size_1-of-1 slds-medium-size_4-of-12 slds-large-size_4-of-12 slds-small-size_12-of-12 slds-p-bottom_medium">
            <lightning:combobox aura:id="teamSelect" 
                                name="teamSelect" 
                                label="Select a Team" 
                                required="true" 
                                messageWhenValueMissing="Please select a Team to proceed."
                                options="{!v.teamOptions}"
                                placeholder="Select a Team"
                                onchange="{!c.handleTeamSelect}"
                                value="{!v.selectedTeam}"
                                disabled="{!v.oppProduct.MKS_IsConverted__c || v.oppProduct.MKS_IsMigrated__c}"/>       
        </div>
        <div class="slds-col slds-size_1-of-1 slds-medium-size_4-of-12 slds-large-size_4-of-12 slds-small-size_12-of-12 slds-p-bottom_medium">
            <lightning:combobox aura:id="productSelect" 
                                name="productSelect" 
                                label="Select a Product" 
                                required="true" 
                                messageWhenValueMissing="Please select a Product to proceed."
                                options="{!v.productOptions}"
                                placeholder="Select a Product"
                                onchange="{!c.handleProductSelect}"
                                disabled="{!v.selectedTeam == null || v.selectedTeam.length == 0 || v.oppProduct.MKS_IsConverted__c || v.oppProduct.MKS_IsMigrated__c}"
                                value="{!v.selectedProduct}"/>
        </div>

Controller:
    handleTeamSelect : function(component, event, helper){
        var selectedTeam = event.getParam("value");
        component.set("v.selectedTeam", selectedTeam);
        helper.getProducts(component, event);
        component.find("productSelect").set("v.disabled", false);
        component.find("productSelect").set("v.value", false);
        component.find("strategySelect").set("v.value", false);
        component.set("v.selectedProduct", null);
        component.set("v.selectedStrategy", null);
    },
    
    //method to handle product selection and render available strategies for selection
    handleProductSelect : function(component, event, helper){
        component.find("productSelect").setCustomValidity("");
        var selectedProduct = event.getParam("value");
        component.set("v.selectedProduct", selectedProduct);
        component.set("v.selectedStrategy", null);
        helper.getStrategies(component, event);
        component.find("strategySelect").set("v.disabled", false);
        component.find("strategySelect").set("v.value", false);
    },

Helper :
    //helper method to get all available teams for selection
    getTeams : function(component){
        var action = component.get("c.getStrategies");
        action.setStorable();
        action.setCallback(this, function(response){
            var state = response.getState();
            if (component.isValid() && state === "SUCCESS") {
                var result = JSON.parse(response.getReturnValue());
                component.set("v.hierarchy", result);
                console.log('Team size: '+result.teams.length);
                var teamOptions = "[";
                for(var i = 0; i< result.teams.length; i++){
                    teamOptions += "{ \"value\": \""+result.teams[i].id+"\", \"label\": \""+result.teams[i].name+"\"},";
                }
                if(teamOptions.length > 1){
                    teamOptions = teamOptions.slice(0, -1);
                }
                teamOptions += "]";
                var teamList = JSON.parse(teamOptions);
                console.log('team options: '+teamList);
                component.set("v.teamOptions", teamList);
            }
        });
        $A.enqueueAction(action);
    },
    
    //helper method to get products available for the selected team
    getProducts : function(component, event){
        var teamId = component.get("v.selectedTeam");
        var heir = component.get("v.hierarchy");
        var oppProduct = component.get("v.oppProduct");
        var prods = [];
                if(oppProduct == null || (oppProduct != null && !oppProduct.MKS_IsMigrated__c)){
            for(var i = 0; i < heir.teams.length; i++){
                if(heir.teams[i].id == teamId){
                    prods = heir.teams[i].products;
                    break;
                }
            }
        }else{
            for(var i = 0; i < heir.products.length; i++){
                if(oppProduct.Product2Id == heir.products[i].id){
                    prods.push(heir.products[i]);
                    break;
                }
            }
        }
         component.set("v.products", prods);
        
        var prodOptions = "[";
        for(var i = 0; i < prods.length; i++){
            prodOptions +=  "{ \"value\": \""+prods[i].id+"\", \"label\": \""+prods[i].name+"\"},";   
        }
        if(prodOptions.length > 1){
            prodOptions = prodOptions.slice(0, -1);
        }
        prodOptions += "]";
        var prodList = JSON.parse(prodOptions);
       component.set("v.productOptions", prodList);
    },

Thanks 
VRK

 
ShivankurShivankur (Salesforce Developers) 
Hi There,

I could find there was a known issue with similar requirement in Spring'19.

Here is the link: https://trailblazer.salesforce.com/issues_view?id=a1p3A00000031nUQAQ&title=dependent-picklists-does-not-respect-the-sort-order-of-field-values-using-flowruntime-dependentpicklists

If you think this is a bug/non-functional from platform end, then its recommended to raise a case with Salesforce support to work on this to verify if its regression issue.

Hope above information helps. Please mark as Best Answer so that it can help others in future.

Thanks.