0

I have a problem with my code

export default class PdmNewModalPlist extends LightningElement {
    @api objectName;
    @api fieldName;
    @api apiName;
    @api recordTypeId;
    @track obj;
    @wire(getPicklistValues, { 
        recordTypeId:'$recordTypeId',
        fieldApiName: { 
            fieldApiName: *this.fieldName*, 
            objectApiName: *this.objectName*
        }
    })
    PicklistValues;
}

In marked places i want to call variables but that's don't work. Propably because 'this' context shows function not document. How i can change 'this' context or make this function works?

3

You want to use reactive variables:

    @wire(getPicklistValues, { 
        recordTypeId:'$recordTypeId',
        fieldApiName: { 
            fieldApiName: '$fieldName', 
            objectApiName: '$objectName'
        }
    })
    PicklistValues;

You can read more in Understand the Wire Service.

1
  • still not work. When i consolLog picklistValue i get: handler: de membrane: {valueDistortion: function, valueMutated: function, valueObserved: function, valueIsObservable: function, objectGraph: WeakMap} originalTarget: Object data: undefined error: fp {status: 403, body: {message: "You don't have access to this record. Ask your administrator for help or to request access.", statusCode: 403, errorCode: "INSUFFICIENT_ACCESS"}, headers: {} – Kamil Motyka May 6 '20 at 16:43
2

'This' context isn't a problem here, The main problem is an execution order. @Sfdcfox's solution won't work because values will be 'undefined'. The solution that works for me is creating an object in connectedCallback function and pass that object to @wire function

 connectedCallback(){
        this.obj = { fieldApiName: this.fieldName, objectApiName: this.objectName};
     }

 @wire(getPicklistValues, { recordTypeId:'$recordTypeId' , fieldApiName: '$obj' })
                                PicklistValues;  
1
  • 1
    This is the correct solution, although I'm not sure why it is so. The getPicklistValues adapter should work just like the other ones, but for some reason, you do have to set a new variable in connectedCallback in order for this to work – willard Nov 29 '20 at 6:01

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.