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

2 Answers 2

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, 2020 at 13:45
0

Anyone know if you can get the label dynamically? Consider the Related List for History. It always shows the Label. The above solution, when correctly coded, works but only if you hardcode a condition for any expected field/label.

Is there are way to get the History without even knowing what fields might be present and have the Labels rendered correctly? (Gosh darn why doesn't SF just put FieldLabel in the Object__History ???)

You must log in to answer this question.

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