0

I have a template using for:each to display multiple records. I need to display the current values of a multi select picklist in that template. Can someone guide me in getting the current values populated in the lightning-dual-listbox? I am able to get the available options by using the wire service / getPicklistValues but I can't figure out how to populate the current values from the array. Here is the html:

<template for:each={clonedGroupStructures} for:item="cgs">
      <div key={cgs.Id}>
        <div class="slds-box  slds-p-left_medium slds-p-right_medium" >       
            <div class="slds-grid ">
                
                <div class="slds-col">
                        <lightning:layoutItem  class="customMain" > 
                            <template if:true={StatusValues.data}>
                                <lightning-combobox name="Status"
                                                    label="Status"
                                                    value={cgs.Status__c}
                                                    placeholder="-Select-"
                                                    options={StatusValues.data.values}
                                                    onchange={handleFundingTypeChange} >
                                </lightning-combobox>
                            </template><br/>
                        </lightning:layoutItem>
                        
                </div>
                <div class="slds-col">
                        <lightning:layoutItem  class="customMain" > 
                            <template if:true={CcatValues.data}>
                                <lightning-dual-listbox  name="Coverage Category"
                                                    label="Coverage Category"
                                                    
                                                    placeholder="-Select-"
                                                    options={CcatValues.data.values}
                                                    onchange={handleFundingTypeChange} >
                                </lightning-dual-listbox >
                            </template><br/>
                        </lightning:layoutItem>
                </div>
             </div>
          </div>
  </template

1 Answer 1

0

The picklist will be in the data attribute returned by getPicklistValues within values. You can access them like. And Since, the returned list is already in option format it can be used directly like,

@wire(getPicklistValues, {
        recordTypeId: "012000000000000AAA",
        fieldApiName: INDUSTRY_FIELD
      })
      setPicklistOptions({ error, data }) {
        console.log({ error, data });
        if (data) {
          this.values = data.values;
        } else if (error) {
          console.log(error);
        }
      }

& html part would be simple,

<template>
    <lightning-dual-listbox label="Picklists" source-label="Available Options" selected-label="Selected Options"
        options={values}></lightning-dual-listbox>
</template>
3
  • thanks for responding Sachin. I am not looking to populate the "options" but the actual "values" of my array.
    – Frank
    Jan 21, 2021 at 19:06
  • You mean some preselected values? Jan 21, 2021 at 19:07
  • This is a clone function. So the user selects a record and it copies that record to an array "x" number of times. Now I have an array and need to display that array as a list of editable records. The user will make changes and then save the new rows. I need to get the original records values for the multi select picklist populated in the dual listbox. All other field types (like the status field in my posted code) appear by just using their field name. But not for the dual listbox.
    – Frank
    Jan 21, 2021 at 19:22

You must log in to answer this question.

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