Hello I want to pass the IsConverted value into a variable and retrieve it in a function

import { LightningElement,track,api,wire} from 'lwc';
import { getRecord } from 'lightning/uiRecordApi';

const FIELDS = ['Lead.CreatedDate', 'Lead.IsConverted','Lead.ConvertedDate'];

export default class LeadModularTimer extends LightningElement {
    @api recordId;
    @track isConvert ;
    @track lead ;
      @wire(getRecord, { recordId: '$recordId', FIELDS })
      wiredRecord({data }) {
         if (data) {
              this.lead = data;
              this.isConvert = this.lead.fields.IsConverted.value;

          var parentThis = this;
       console.log(parentThis.isConvert);// this is returing undefined 

  • 1
    There's something I don't understand with your code. The isConvert variable is set via your wire method. The method is not called yet when your component initialized. The connectedCallback method is called at init so your isConvert is undefined. What do you want to do with this variable exactly? – Martin Lezer Oct 30 '19 at 16:27
  • thanks for the response @MartinLezer, I want to pass the IsConverted value into the isConvert variable thats it – Aravind Babu B Oct 31 '19 at 7:00
  • Then you don't need the connectedCallback method. Your code is already supposed to work without it. – Martin Lezer Oct 31 '19 at 7:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.