1

Has anyone been able to successfully show picklist values based on record type using lightning components? We have 4 record types and for some reason all record types is defaulting to the RSO record type picklist values.

This is what I have so far and it is not displaying the correct picklist values based on the record type.

Parent Component:

<aura:component controller="BusinessRequest_LightningController" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,forceCommunity:availableForAllPageTypes" access="global">

<!--Initialization-->

<aura:handler name="init" value="{!this}" action="{!c.fetchListOfRecordTypes}"/>


<!--Attribute Setup-->
<aura:attribute name="isOpen" type="Boolean" default="false"/> 
<aura:attribute name="simpleRecord" type="Object"/> 
<aura:attribute name="record" type="Object"/>

<!--Record Type Attributes-->
<aura:attribute name="recordTypeMap" type="Map"/>   
<aura:attribute name="recordTypeChoice" type="String" default="-- None --"/>
<aura:attribute name="recordTypeId" type="Id"/>   

<!--Field Attributes-->
<aura:attribute name="category" type="String"/>  
<aura:attribute name="subcategory" type="String"/>    
<aura:attribute name="status" type="String"/>      
<aura:attribute name="subject" type="String"/>      
<aura:attribute name="description" type="String"/>      
<aura:attribute name="steps" type="String"/>
<aura:attribute name="email" type="String"/> 
<aura:attribute name="date" type="Date"/>
<aura:attribute name="comments" type="String"/>


<!--Object Field Retrieval-->

<force:recordData aura:id="objectFields"
                  recordId="{!v.recordId}" 
                  layoutType="FULL"
                  targetRecord="{!v.record}"
                  targetFields="{!v.simpleRecord}"
                  mode="VIEW"/>

<!-- Title -->

<div class="slds-grid">
    <div class="slds-col slds-has-flexi-truncate">
        <p class="slds-text-heading--large">Business Request</p>
        <div class="slds-grid" style="background-color: #F4F6F9;">
            <div class="slds-grid slds-type-focus slds-no-space">
                <h1 class="slds-text-heading--medium slds-truncate" style="font-weight: bold;" title="Business Request Quick Create">Quick Create</h1><br/><br/>
            </div>
        </div>
    </div>
</div>

<!--Main Form--> 
<form id="mainForm" class="slds-form--stacked">
    <aura:if isTrue="{!v.isOpen}"> 

        <!--Record Type Selection-->
        <div class="slds-form-element slds-is-required">
            <div class="slds-form-element__control" style="width: 175px;">
                <ui:inputSelect aura:id="recordTypes" 
                                class="slds-input"
                                labelClass="slds-form-element__label"               
                                value="{!v.recordTypeChoice}"
                                required="true"
                                change="{!c.getRecordTypeId}"/><br/><br/>
            </div>
        </div>

        <!--RSO Request-->
        <aura:if isTrue="{!v.recordTypeChoice == 'RSO'}">
            <c:BusinessRequest_RSO recordTypeId="{!v.recordTypeId}"
                                   recordTypeMap="{!v.recordTypeMap}"
                                   category="{!v.category}"
                                   comments="{!v.comments}"
                                   email="{!v.email}"
                                   date="{!v.date}"/>             

        </aura:if>

        <!--Legal Request-->
        <aura:if isTrue="{!v.recordTypeChoice == 'Legal'}">
            <div aura:id="legalRecord" class="slds-show">
                <c:BusinessRequest_LegalRequest />            
            </div>
        </aura:if>


        <!--Commision Dispute--> 

        <!--Sales Ops-->        
        <aura:if isTrue="{!v.recordTypeChoice == 'Sales Operations'}">  
            <c:BusinessRequest_SalesOps recordTypeId="{!v.recordTypeId}"
                                        category="{!v.category}"
                                        subcategory="{!v.subcategory}"
                                        status="{!v.status}"
                                        subject="{!v.subject}"
                                        description="{!v.description}"
                                        steps="{!v.steps}"/>
        </aura:if>


    </aura:if>
</form>

RSO Child Component:

<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,forceCommunity:availableForAllPageTypes" access="global">

<!--Attribute Setup-->
<aura:attribute name="showRecordType" type="Boolean" default="false"/>
<aura:attribute name="recordTypeId" type="Id"/> 
<aura:attribute name="recordTypeMap" type="Map"/>
<aura:attribute name="email" type="String"/>
<aura:attribute name="date" type="Date"/>
<aura:attribute name="category" type="String"/>
<aura:attribute name="comments" type="String"/>

<!--RSO Business Request Form--> 
<div aura:id="rsoComponent">

            <!--Lightning Input Field-->

            <lightning:recordEditForm aura:id="rsoRecordCreate"
                                      recordTypeId="{!recordTypeId}"
                                      objectApiName="Business_Request__c">
                <lightning:inputField aura:id="email" fieldName="LMI_Email__c"/>
                <lightning:inputField aura:id="date" fieldName="Request_Date__c"/>
                <lightning:inputField aura:id="category" fieldName="Category__c"/>
                <lightning:inputField aura:id="subcategory" fieldName="Sub_category__c"/>
                <lightning:inputField aura:id="comments" fieldName="Comments__c"/>
            </lightning:recordEditForm>

</div>


<!--Record Type Selection--> 
<aura:if isTrue="{!v.showRecordType}"> 
    <c:BusinessRequest_QuickCreate />
</aura:if>    

Sales Ops Child Component:

<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,forceCommunity:availableForAllPageTypes" access="global">

<!--Attribute Setup-->

<aura:attribute name="recordTypeId" type="Id"/> 
<aura:attribute name="recordTypeMap" type="Map"/>    
<aura:attribute name="category" type="String"/>    
<aura:attribute name="subcategory" type="String"/>     
<aura:attribute name="status" type="String"/>      
<aura:attribute name="subject" type="String"/>      
<aura:attribute name="description" type="String"/>      
<aura:attribute name="steps" type="String"/>

<!-- Sales Operations Business Requests Form --> 

<div aura:id="salesOpsComponent"> 
    <!-- Input Fields -->
    <lightning:recordEditForm aura:id="salesOpsRecordCreate"
                                  recordTypeId="{!recordTypeId}"
                                  objectApiName="Business_Request__c">
        <div class="slds-form" role="list" style="width:700px;">
            <div class="slds-grid slds-gutters_small">
                <div class="slds-col slds-has-flexi-truncate" role="listitem">
                    <div class="slds-form-element slds-form-element_edit slds-hint-parent">
                        <div class="slds-form-element__control">
                            <lightning:inputField aura:id="category" fieldName="Category__c"/>
                        </div>
                    </div>
                </div>
                <div class="slds-col slds-has-flexi-truncate" role="listitem">
                    <div class="slds-form-element slds-form-element_edit slds-hint-parent">
                        <div class="slds-form-element__control">
                            <lightning:inputField aura:id="subcategory" fieldName="Sub_category__c" value="{!v.subcategory}"/><br/><br/>
                        </div>
                    </div>
                </div>
            </div>
            <div class="slds-grid slds-gutters_small" style="width: 360px;">                
                <div class="slds-col slds-has-flexi-truncate" role="listitem">
                    <div class="slds-form-element slds-form-element_edit slds-hint-parent">
                        <div class="slds-form-element__control">
                            <lightning:inputField aura:id="status" fieldName="Status__c" value="{!v.status}"/><br/><br/>
                        </div>
                    </div>
                </div>
            </div>
            <div class="slds-grid slds-gutters_small">
                <div class="slds-col slds-has-flexi-truncate" role="listitem">
                    <div class="slds-form-element slds-form-element_edit slds-hint-parent">
                        <div class="slds-form-element__control">
                            <lightning:inputField aura:id="subject" fieldName="Subject__c" value="{!v.subject}"/><br/><br/>
                        </div>
                    </div>
                </div>
            </div>
            <div class="slds-grid slds-gutters_small">
                <div class="slds-col slds-has-flexi-truncate" role="listitem">
                    <div class="slds-form-element slds-form-element_edit slds-hint-parent">
                        <div class="slds-form-element__control">
                            <lightning:inputField aura:id="description" fieldName="Description__c" value="{!v.description}"/>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </lightning:recordEditForm>   
</div>
<!-- End Sales Operations Business Requests Form --> 

  • 3
    You should reference attributes like "{!v.recordTypeId}", you left off the "v." in your child components – Kyle May 18 '18 at 19:55
  • Thank you so much! I completely missed this. It is now working properly. :) – Kim May 21 '18 at 14:35
2

In this case you were using the lightning:recordEditForm correctly, however you were referencing your recordTypeId incorrectly.

You had recordTypeId="{!recordTypeId}" but instead it should be recordTypeId="{!v.recordTypeId}".

1

To add on this, if you want to pull an existing record's recordtype directly just using the record id include it in the lightning:recordEditForm

<lightning:recordEditForm aura:id="recordEditForm" 
                                  objectApiName="{!v.sObjectName}"
                                  recordTypeId="{!v.recordTypeId}"
                                  recordId="{!v.recordId}">
    <lightning:inputField fieldName="{!v.fieldName}"/>
</lightning:recordEditForm>
  • This is only if we want to pull an existing record and edit it right? If we want to just create new and not edit an existing one, there's no need to add recordId? – Kim May 21 '18 at 14:37
  • That is correct Kim – Glen De Marcos May 22 '18 at 18:21

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.