4

I have implemented a lightning web component (lwc) that shows a dependent picklist field

To load a dependent picklist in lwc I use @wire with getPicklistValues and because getPicklistValues requires a record type id, I use another @wire to get the default record type id - getObjectInfo. this is my code:

import { LightningElement, api, track, wire } from 'lwc';
import { getObjectInfo } from 'lightning/uiObjectInfoApi';
import { getPicklistValues } from 'lightning/uiObjectInfoApi';

import CASE_OBJECT from '@salesforce/schema/Case';
import PICKLIST_FIELD from '@salesforce/schema/Case.myDependentField__c';

export default class myComponent extends LightningElement {

    @api parentFieldValue;
    @track dependentFieldValues = [];

    @wire(getObjectInfo, { objectApiName: CASE_OBJECT })
    caseObjectInfo;

    @wire(getPicklistValues, { recordTypeId: '$caseObjectInfo.data.defaultRecordTypeId', fieldApiName: PICKLIST_FIELD })
    fieldPicklistValues({error, data}) {
        if(data) {
            let categoryOptions = [];

            // get the selected parent_field index  - to select all it's available values
            let parentIndex = data.controllerValues[this.parentFieldValue];

            // Case Parent Control Field Picklist values
            data.values.forEach(key => {
                // search for the parent index in all the validFor attributes
                for (let i=0; i<key.validFor.length; i++) {
                    if (key.validFor[i] === parentIndex) {
                        categoryOptions.push({
                            label: key.label,
                            value: key.value
                        });
                    }
                }
            });
            this.dependentFieldValues = categoryOptions;
        }
        else if(error) {
            alert(JSON.stringify(error));
        }
    }
}

PROBLEM

This works perfect in all browsers except in internet explorer 11.

In ie11 when I get into the 2nd @wire event - the caseObjectInfo is empty, that means that the 1st @wire did not execute yet. to check this I have added this line inside the fieldPicklistValues method:

console.log('run fieldPicklistValues: ' + JSON.stringify(this.caseObjectInfo));

I've got an empty object in my console for that execution.

WORKAROUND

So what I have done to overcome this is to set the recordTypeId hard coded and now it works well also in ie11 (no need for the 1st @wire).

QUESTION

Can I resolve this ie11 problem without hard-coding my recordTypeId?

2
  • If you are not looking for a quick fix you can use imperative apex and without using only @wire property.
    – Atlas Can
    Commented Dec 24, 2019 at 10:39
  • 1
    @AtlasCan thanks but I do not want to use apex only because of this problem - my current workaround is much better than an apex approach Commented Dec 24, 2019 at 10:43

0

You must log in to answer this question.