1

With this code I trie to verify if the field Code__c that is a string , if the field contains the value 'BC' the Visibily should be false but when I trie this code I get this error .

Uncaught (in promise) TypeError: LWC component's @wire target property or method threw an error during value provisioning. Original error:
[Cannot read properties of undefined (reading 'includes')]

My Code :

import FIELD from '@salesforce/schema/MyContact__c.Account__r.Code__c';
import {getRecord,getFieldValue} from 'lightning/uiRecordApi';
  @track Visibily = false;
    @track value;
    @wire(getRecord, { recordId: '$recordId', fields: [FIELD] })
    dippingN({ data, error }) {
        if (data) {
            this.value == data.fields.Account__r.Code__c;
            if (this.value.includes('BC')) {
                this.Visibily = false;
            }else{
                this.Visibily = true;
            }
        }
    };

1 Answer 1

1

Looks like the property this.value can be undefined.

Add a Null/undefined check to your code to make it not fail

@track Visibily = false;
@track value;
@wire(getRecord, { recordId: '$recordId', fields: [FIELD] })
dippingN({ data, error }) {
    if (data) {
        this.value == data.fields.Account__r.Code__c;
        if(this.value) {
          if (this.value.includes('BC')) {
            this.Visibily = false;
        } else {
            this.Visibily = true;
        }
      } else {
         this.Visibily = true;
       }

    }
};
3
  • 1
    I tried your code and I added also one console to see what I have value , and like you said I get value is undefined , I think this is the problem
    – laila19
    Jan 16, 2023 at 16:23
  • Check my updated answer and make sure to add an undefined check and you should be good! Jan 16, 2023 at 16:24
  • thank you for your help
    – laila19
    Jan 16, 2023 at 17:32

You must log in to answer this question.

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