My requirement is to get picklist values from a record type if the object has more than one record type. Some examples are given with default record value passed. But in my requirement record type is not a default record type.
I tried below example but it didn't work. orderTypeOption is not populating with values. Use the recipe app from a sample gallery in my dev org.
wireGetPicklistValues.html
<template>
<lightning-card title="WireGetPicklistValues" icon-name="custom:custom67">
<div class="slds-m-around_medium" >
Order type picklist
<template if:true={orderTypeOption.data}>
<lightning-combobox
name="progress"
label="Order Type"
value={orderType}
options={orderTypeOption.data.values}
></lightning-combobox>
</template>
</div>
<template if:true={picklistValues.data}>
<div class="slds-m-around_medium">
<template for:each={picklistValues.data.values} for:item="item">
<lightning-input
key={item.value}
label={item.label}
data-value={item.value}
type="checkbox"
>
</lightning-input>
</template>
</div>
</template>
<template if:true={picklistValues.error}>
<c-error-panel errors={picklistValues.error}></c-error-panel>
</template>
<c-view-source source="lwc/wireGetPicklistValues" slot="footer">
Get the picklist values for a specified field. In this example,
the
<strong>Type</strong> field of the <strong>Account</strong> object.
</c-view-source>
</lightning-card>
</template>
wireGetPicklistValues.js
import { LightningElement, wire, track } from 'lwc';
import { getPicklistValues } from 'lightning/uiObjectInfoApi';
import { getObjectInfo } from 'lightning/uiObjectInfoApi';
import TYPE_FIELD from '@salesforce/schema/Account.Type';
import ORDERTYPE_FIELD from '@salesforce/schema/Order.Type';
export default class WireGetPicklistValues extends LightningElement {
@track orderType;
@wire(getPicklistValues, {
recordTypeId: '012000000000000AAA',
fieldApiName: TYPE_FIELD
})
picklistValues;
@wire(getPicklistValues, {
recordTypeId: '$recordTypeId',
fieldApiName: ORDERTYPE_FIELD
})
orderTypeOption;
get recordTypeId() {
// Returns a map of record type Ids
const rtis = this.objectInfo.data.recordTypeInfos;
return Object.keys(rtis).find(rti => rtis[rti].name === 'Asia');
}
}