1

I'm struggling to obtain the values that are part of the Selected list on a lightning-dual-box field.

This is the field:

<lightning-dual-listbox
                name="Mass_Payments__c"
                label="Mass Payment"
                source-label="Available"
                selected-label="Selected"
                required
                value={currentMassPayment}
                options={picklistMassPayments}>
        </lightning-dual-listbox>

On the UI looks like this:

enter image description here

This are parts of the JS that affects that dual listbox, all the other fields are working just fine:

import { getFieldValue, getRecord } from 'lightning/uiRecordApi';
import MASS_PAYMENT_FIELD from '@salesforce/schema/Opportunity.Mass_Payments__c';


export default class Createdealmasspayments extends LightningElement {
opportunityObject = OPPORTUNITY_OBJECT;

@wire(getRecord, {
    recordId: '$recordId', fields: [MASS_PAYMENT_FIELD]
  })
  record;

@wire(getObjectInfo, { objectApiName: OPPORTUNITY_OBJECT })
   handleResult ({ error, data }) {
     if (data) {
     this.rtId = data.defaultRecordTypeId;
   }
 }

  @wire(getPicklistValues, { recordTypeId: '$rtId', fieldApiName:
  MASS_PAYMENT_FIELD })
   getPicklistValuesMassPayments ({ error, data }) {
    if (data) {
     this.picklistMassPayments = data.values;
   }
 }

 // All good until now, this getter is not doing his job
  get currentMassPayment () {
  return this.record.data ? getFieldValue(this.record.data, MASS_PAYMENT_FIELD) : '';

 }

If I select an option and pass it to the 'Selected' block after clicking the correct arrow on the record page layout, before opening this form, the option don't stay on the 'Selected' block. All options are back to the 'Available' block... any ideas on how to work around this?

0

Ok, I got it mow. Basically we are passing a list to our LWC component on get currentMassPayment () , we need to split the incoming data because it can contain more than one value :( ....

All we do is to create a property @track currentMassPaymentSelectedList = []; and make a few changes on the getter, we going to incorporate .split(';');

get currentMassPayment () {
this.currentMassPaymentSelectedList = this.record.data ? getFieldValue(this.record.data, MASS_PAYMENT_FIELD).split(';') : '';
return this.currentMassPaymentSelectedList;

On the HTML we also make a small adjustment:

<lightning-dual-listbox
                name="Mass_Payments__c"
                label="Mass Payment"
                source-label="Available"
                selected-label="Selected"
                required
                value={currentMassPayment}
                options={picklistMassPayments}>
        </lightning-dual-listbox>

Now the values selected on the dual listbox are displayed when firing this LWC action...

  • Curious, is there a reason you went with multiple @wires instead of imperative apex? – Atlas Can Nov 18 at 6:11
  • Basically I have a bunch of @wire(getPicklistValues,... on that component and I'm using lightning-record-edit-form. You can use imperative apex or even a @wire(getRecord, { recordId: '$recordId', fields: FIELDS }) wiredRecord({ error, data }) {... approach – Carlos Naranjo Nov 18 at 21:41

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.