0

I have lwc. In there i get some of the fields from UI and some from apex and display it. But when I get the fields value and assign it to value fields in common fields array it's not display the values there. common fields debug does not have a value. Does someone know the reason? Please find the sample code below.

@api recordId;
objValue;
name;
phone;
primaryAddress;
tierOne;
tierTwo;
ecidValue;
ecidValue;
addressLineOne;
addressLineTwo;
addressLineThree;
countryCode;
city;
postalCode;
province;
country;
telephoneExte;
email;
fax;
@track objMetadataValues = {};
@track mapCustGroup = [];
@api targetSystemval;
result;
error;
@track initCustomerRequest = { isModelOpen: false, targetSystem: '' ,uiFields:''};
uiFields;

@wire(getRecord, { recordId: '$recordId', fields: '$fields' })
wiredRecord({ error, data }) {
    if (data) {
        console.log("data", JSON.stringify(data));
        this.objValue = data;
        if(data.apiName == 'Account'){
            this.name = this.objValue.fields.Name.value;
            this.phone = this.objValue.fields.Phone.value;
            this.primaryAddress = this.objValue.fields.Primary_Address_1__c.value;
            this.tierOne = this.objValue.fields.Tier_1_Classification__c.value;
            this.tierTwo = this.objValue.fields.Tier_2_Classification__c.value;
            this.ecidValue = this.objValue.fields.ECID__c.value;
            this.addressLineOne = this.objValue.fields.Primary_Address_1__c.value;
            this.addressLineTwo = this.objValue.fields.Primary_Address_2__c.value;
            this.addressLineThree = this.objValue.fields.Primary_Address_3__c.value;
            this.email = this.objValue.fields.Email__c.value;
            this.countryCode = this.objValue.fields.Primary_Country_Code__c.value;
            this.city = this.objValue.fields.Primary_City__c.value;
            this.postalCode = this.objValue.fields.Primary_Zip_Postal_Code__c.value;
            this.province = this.objValue.fields.Primary_State_Province__c.value;
            this.country = this.objValue.fields.Primary_Country__c.value;
            this.telephoneExte = this.objValue.fields.Phone_Extension__c.value;
            this.fax = this.objValue.fields.Fax.value;
        }else{
            this.name = this.objValue.fields.Name.value;
            this.phone = this.objValue.fields.Phone.value;
            this.primaryAddress = this.objValue.fields.Primary_Address_1__c.value;
            this.ecidValue = this.objValue.fields.ECID__c.value;
            this.addressLineOne = this.objValue.fields.Primary_Address_1__c.value;
            this.addressLineTwo = this.objValue.fields.Primary_Address_2__c.value;
            this.addressLineThree = this.objValue.fields.Primary_Address_3__c.value;
        }

    }else{
        this.error= error;
    }
}

commonFields = [
    { input: false, text: true, combobox: false, required: false, errorMessage: '', disabled: false, label:'Target System' , value: this.targetSystemval},
    { input: false, text: true, combobox: false, required: false, errorMessage: '', disabled: false, label:'ECID' , value: this.ecidValue},
    { input: false, text: true, combobox: false, required: false, errorMessage: '', disabled: false, label:'Email' , value: this.email},
    { input: false, text: true, combobox: false, required: false, errorMessage: '', disabled: false, label:'AddressLine 1' , value: this.addressLineOne },
    { input: false, text: true, combobox: false, required: false, errorMessage: '', disabled: false, label:'AddressLine 2' , value: this.addressLineTwo},
    { input: false, text: true, combobox: false, required: false, errorMessage: '', disabled: false, label:'AddressLine 3' , value: this.addressLineThree},
    { input: false, text: true, combobox: false, required: false, errorMessage: '', disabled: false, label:'City' , value: this.city},
    { input: false, text: true, combobox: false, required: false, errorMessage: '', disabled: false, label:'Zip/Postal Code' , value: this.postalCode},
    { input: false, text: true, combobox: false, required: false, errorMessage: '', disabled: false, label:'State/Province Code' , value: this.province},
    { input: false, text: true, combobox: false, required: false, errorMessage: '', disabled: false, label:'Country Code' , value: this.countryCode},
    { input: false, text: true, combobox: false, required: false, errorMessage: '', disabled: false, label:'Fax' , value: this.fax}
];
        
        
handleCustomerRequest(event){
    console.log('this.ecidValue ' +this.ecidValue + 'this.email: ' +this.email);
    this.targetSystemval = event.detail.core;
    this.uiFields = JSON.parse(JSON.stringify(this.commonFields));
    this.displayCustomerRequest = true;
    console.log('event.detail.core: ' +event.detail.core);
    console.log('this.targetSystemval ' +this.targetSystemval);
    console.log('JSON.parse(JSON.stringify(this.commonFields)): ' +JSON.parse(JSON.stringify(this.commonFields)));
    console.log('common fields' +JSON.stringify(this.commonFields));
  
}

1 Answer 1

0

This is because the wire method will be called after the initialization for the commonFields array. You should initialize/reinitialize the array after loading the data.

wiredRecord({ error, data }) {
    if (data) {
        this.objValue = data;
        if(data.apiName == 'Account'){
            ... // omitting this code
        }
        this.commonFields = [
            { input: false, text: true, combobox: false, required: false, errorMessage: '', disabled: false, label:'Target System' , value: this.targetSystemval},
            { input: false, text: true, combobox: false, required: false, errorMessage: '', disabled: false, label:'ECID' , value: this.ecidValue},
            { input: false, text: true, combobox: false, required: false, errorMessage: '', disabled: false, label:'Email' , value: this.email},
            { input: false, text: true, combobox: false, required: false, errorMessage: '', disabled: false, label:'AddressLine 1' , value: this.addressLineOne },
            { input: false, text: true, combobox: false, required: false, errorMessage: '', disabled: false, label:'AddressLine 2' , value: this.addressLineTwo},
            { input: false, text: true, combobox: false, required: false, errorMessage: '', disabled: false, label:'AddressLine 3' , value: this.addressLineThree},
            { input: false, text: true, combobox: false, required: false, errorMessage: '', disabled: false, label:'City' , value: this.city},
            { input: false, text: true, combobox: false, required: false, errorMessage: '', disabled: false, label:'Zip/Postal Code' , value: this.postalCode},
            { input: false, text: true, combobox: false, required: false, errorMessage: '', disabled: false, label:'State/Province Code' , value: this.province},
            { input: false, text: true, combobox: false, required: false, errorMessage: '', disabled: false, label:'Country Code' , value: this.countryCode},
            { input: false, text: true, combobox: false, required: false, errorMessage: '', disabled: false, label:'Fax' , value: this.fax}
        ];

    }else{
        this.error= error;
    }
}
3
  • Thank You @sfdcfox Commented Feb 27, 2022 at 7:40
  • small clarification when i run the code as mentioned i am getting value except targetsystem because it's assign value when i click a handleCustomerRequest,Do i need to again put that this.commonfields with value in there too Commented Feb 27, 2022 at 11:33
  • @Basu If I understand your question correctly, I presume yes. Commented Feb 27, 2022 at 15:28

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.