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.

| improve this answer | |
  • 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 at 16:43
1

'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;  
| improve this answer | |

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.