0

I am writing an LWC component to display history object results of a custom object. I am unable to retrieve field label from "FIELD" in _history object. Tried to build the logic in component.js, you can see from the code i have assigned the value "Total Price" to "Totalprice__c" field. But this applies to entire row in my result even for other fields also.

Any help would be appreciated.

Below is my code:

Component.JS

import { LightningElement, wire, track } from 'lwc';

import getTenantDetailList from '@salesforce/apex/Testcurrenycontroller.getPriceDetailList';


// Datatable Columns
const columns = [
{
    label: 'Old Value',
    fieldName: 'OldValue',
    type: 'text',
}, {
    label: 'New Value',
    fieldName: 'NewValue',
    type: 'text'
}, {
    label: 'Field',
    fieldName: 'Field',
    type: 'text'
}, {
    label: 'Created Date',
    fieldName: 'CreatedDate',
    type: 'Date'
}, {
    label: 'CreatedById',
    fieldName: 'CreatedById',
    type: 'Id'
}
];


export default class ReferenceDataInLwcDatatable extends LightningElement {
@track data = [];
@track columns = columns;

@wire(getPriceDetailList)
opp({error, data}) {

    if(data) {
        let currentData = [];
       // let fielddata = [];
        var Data = [];
     data.forEach((row) => {

            let rowData = {};
            rowData.Id = row.Id;
            rowData.OldValue = row.OldValue;
            rowData.NewValue = row.NewValue;
            //rowData.Field = row.Field;

            if (rowData.Field = 'TotalPrice__c' ) {
            Data = 'Total price';

            }

            rowData.Field = Data;
            currentData.push(rowData);
        });

        this.data = currentData;
    }
    else if(error) {
        window.console.log(error);
    }
}
}

RESULT: enter image description here

Result

1

= is assignment, while == or === is equality. You're actually assigning the value TotalPrice__c to the variable rowData.field, and this results in a "truthy" value, so it always matches. To fix it:

if (rowData.Field === 'TotalPrice__c' ) {
1
  • @BalaKrishna In your example, that line of code is commented out?
    – sfdcfox
    Apr 28 '20 at 13:45

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.