1

I am trying to implement a LWC component in my flow based on the record type. So when the case has a specific recordType only the value for this recordType are shown on the screen component. here is what I have done so far.. enter image description here

The fields are showing but I am not able to select the values. enter image description here

Basically if I select: Type: Administration Case Category should display the dependent values for Administration enter image description here

But I can't make my dependent picklist work. Here is what I have done on VS code:

requestTypePiclkistValues.html

<template>
   <lightning-record-edit-form object-api-name={objectName} record-type-id={recordTypeId} >
       <lightning-input-field field-name={fieldName} value={fieldValue} required={isRequired} onchange={handleFieldChange} ></lightning-input-field>
       <lightning-input-field field-name={dependentFieldName} value={fieldValue} required={isRequired} onchange={handleFieldChange} ></lightning-input-field>
   </lightning-record-edit-form> 
</template>

requestTypePiclkistValues.js

    import { LightningElement, api } from 'lwc';
 
export default class RequestTypePicklistValues extends LightningElement {
   /* Required Attributes */
   // {String} API Name of Object
   @api objectName;
   // {String} API Name of Picklist value (for this specific Object)
   @api fieldName;
   @api dependentFieldName;
   // {String} Id of RecordType the picklist values should be restricted with
   @api recordTypeId;
 
   /* Optional Attributes */
   // {Boolean} Whether or not the input is required
   @api isRequired;
   // {String} Error message non selected
   @api errorMessage;
 
   /* Output Attributes */
   // {String} API value of selected picklist value (not the label, but the value)
   @api fieldValue;
 
   // {Validation} Function Lightning Flows execute on 'next'-button to validate whether component is valid
   @api validate() {
       if( !this.isRequired
           || ( this.isRequired && this.fieldValue && this.fieldValue.length > 0 ) ){
           return { isValid: true };
       } else {
           return {
               isValid: false,
               errorMessage: this.errorMessage
            };
        }
   }
 
   /**
    * Function to handle the picklist selection and assign to the fieldValue variable
    */
   handleFieldChange( event ){
       this.fieldValue = event.target.value;
   }
}

requestTypePiclkistValues.js-meta.xml

    <?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
   <apiVersion>50.0</apiVersion>
   <description>Request RecordType Values</description>
   <isExposed>true</isExposed>
   <targets>
       <target>lightning__FlowScreen</target>
       <target>lightning__RecordPage</target>
   </targets>
   <targetConfigs>
       <targetConfig targets="lightning__RecordPage" >
           <property name="objectName" type="String" label="Object Name" required="true" />
           <property name="recordTypeId" type="String" label="RecordTypeId" required="true" />
           <property name="fieldName" type="String" label="Field to show picklist values for" required="true" />
           <property name="dependentFieldName" type="String" label="Field to show picklist values for" required="true" />
       </targetConfig>
       <targetConfig targets="lightning__FlowScreen" >
           <property name="objectName" type="String" label="1) Object API Name" role="inputOnly" />
           <property name="fieldName" type="String" label="2) Picklist 1 API Name" role="inputOnly" />
           <property name="dependentFieldName" type="String" label="3) Picklist 2 API Name" role="inputOnly" />
           <property name="recordTypeId" type="String" label="4) RecordTypeId" role="inputOnly" description="Id of RecordType Id, fetch from record {!sObj_Case.RecordTypeId} or from Get {!Get_RecordType.Id}" />
           <property name="isRequired" type="Boolean" label="5) Required input" role="inputOnly" default="false" />
           <property name="errorMessage" type="String" label="6) Error message" role="inputOnly" description="Error message shown to customer when input required, but not populated" default="Please select a picklist value"/>
           <property name="fieldValue" type="String" label="Selected value by user" description="The API value of the selected Picklist value" />
       </targetConfig>
   </targetConfigs>
   <masterLabel>Request RecordType Values</masterLabel>
 
</LightningComponentBundle>

1 Answer 1

-2

I solved it:

----------html----------

        <!-- Picklist by RecordType -->
        <lightning-input-field 
            field-name={fieldName} 
            value={fieldValue} 
            required={isRequired} 
            onchange={handleFieldChange} >
        </lightning-input-field>

        <!-- Picklist Dependency -->
        <lightning-input-field 
            field-name={fieldNameDep} 
            value={fieldValueDep} 
            required={isRequiredDep} 
            onchange={handleFieldChangeDep} >
        </lightning-input-field>

    </lightning-record-edit-form>

</template>

----------js----------

import { LightningElement, api } from 'lwc';

export default class RecordType_PicklistValues extends LightningElement {

    @api fieldName;
    @api recordTypeId;
    @api isRequired;
    @api errorMessage;
    @api fieldValue;


    @api fieldNameDep;
    @api isRequiredDep;
    @api fieldValueDep;

    @api validate() {
        if( !this.isRequired
            || ( this.isRequired && this.fieldValue && this.fieldValue.length > 0 ) ){
            return { isValid: true };
        } else {
            return {
                isValid: false,
                errorMessage: this.errorMessage
             };
         }
    }

    handleFieldChange( event ){
        this.fieldValue = event.target.value;
    }

    handleFieldChangeDep( event ){
        this.fieldValueDep = event.target.value;
    }
}

----------xml----------

<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
    <apiVersion>48.0</apiVersion>
    <description>RecordType Picklist Values</description>
    <isExposed>true</isExposed>
    <targets>
        <target>lightning__FlowScreen</target>
        <target>lightning__RecordPage</target>
    </targets>
    <targetConfigs>
        <targetConfig targets="lightning__RecordPage" >
            <property name="objectName" type="String" label="Object Name" required="true" />
            <property name="recordTypeId" type="String" label="RecordTypeId" required="true" />
            <property name="fieldName" type="String" label="Field to show picklist values for" required="true" />
        </targetConfig>
        <targetConfig targets="lightning__FlowScreen" >
            <property name="objectName" type="String" label="SObject" role="inputOnly" />
            <property name="fieldName" type="String" label="API Name do campo" role="inputOnly" />
            <property name="recordTypeId" type="String" label="Id do Tipo de Registro" role="inputOnly" description="Id of RecordType Id, fetch from record {!sObj_Account.RecordTypeId} or from Get {!Get_RecordType.Id}" />
            <property name="isRequired" type="Boolean" label="Campo Obrigatório" role="inputOnly" default="false" />
            <property name="errorMessage" type="String" label="Mensagem de erro" role="inputOnly" description="Error message shown to customer when input required, but not populated" default="Please select a picklist value"/>
            <property name="fieldValue" type="String" label="Valor selecionado pelo usuário" description="The API value of the selected Picklist value" />

            <property name="fieldNameDep" type="String" label="API Name do campo com dependência" role="inputOnly" />
            <property name="isRequiredDep" type="Boolean" label="Campo com dependência obrigatório" role="inputOnly" default="false" />
            <property name="fieldValueDep" type="String" label="Valor selecionado do campo com dependência" description="The API value of the selected Picklist value" />
        </targetConfig>
    </targetConfigs>
    <masterLabel>RecordType Picklist Values</masterLabel>
</LightningComponentBundle>
2
  • 2
    Thank you for this! Just one remark: Your answer would profit a lot from a depiction of the underlying idea of your code. As such many people look at this as a "code dump"... Jun 17, 2022 at 11:59
  • Welcome to Salesforce Stack Exchange (SFSE)! Thank you for your contribution. Here on SFSE the why (explanation) is often as or more important than the how (code) in an answer - especially since it can help future searchers/readers. Please edit your answer to explain - even briefly (but enough to understand) - why your code solves the problem.
    – Moonpie
    Jun 17, 2022 at 12:34

You must log in to answer this question.

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