• Sumit Kushwaha
  • NEWBIE
  • 0 Points
  • Member since 2022

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
let jsonFromNet = JSON.stringify(this.conList);
        console.log('stringyfy ==>> ' + jsonFromNet);
       
        let contactObject = JSON.parse(jsonFromNet);
        console.log('parsing ==>> ' + contactObject);
// this avoce console shows [object object]
how to change object to show field Name ??
        console.log('columns----- ' , columns.fieldName);
I try to build my own LWC Datatable component on Work Order object - which will show related Work Order Line Items records. The table is empty. How to retrieve the records into my LWC?
Here is my code:
woliDatatableDemo.html
<template>
    <lightning-card title="NEW Work Order Line Item" icon-name="custom:custom63">
            <div style="width: auto;">
                    <lightning-datatable
                        key-field="Id"
                        data={data}
                        columns={columns}
                        ></lightning-datatable>
                     </div>
        </lightning-card>
    </template>

woliDatatableDemo.js
import { LightningElement, api, track, wire } from "lwc";
import getWOLIs from '@salesforce/apex/woliControllerDatatable.getWOLIs';

const columns = [
    {
        label: 'Device', fieldName: 'AssetId'
    },

    { label: 'Serial No.', fieldName: 'Serial_No__c'},

    { label: 'Product', fieldName: 'PricebookEntryId'},

    { label: 'Quantity', fieldName: 'Quantity'},

    { label: 'List Price', fieldName: 'ListPrice'},

    { label: 'Discount', fieldName: 'Discount'},

    { label: 'Total Price', fieldName: 'TotalPrice'},
    
];

export default class WoliDatatableDemo extends LightningElement {

    @api recordId;
    @track data = [];
    @track columns = columns;
    
  
    @wire(getWOLIs, { woid: "$recordId" })
    
    wiredRecordsMethod({ data, error }) {
    if (data) {
       let result = JSON.parse(JSON.stringify(data));
        this.data = result.map(function(item) {
          return item;
        })
      this.error = undefined;
    } else if (error) {
      this.error = error;
      this.data = undefined;
    }
}
}

woliControllerDatatable.cls
public with sharing class woliControllerDatatable {

    @AuraEnabled(cacheable=true)
    public static List<WorkOrderLineItem> getWOLIs(String woId) {
        return [
            SELECT Quantity, PricebookEntryId, Serial_No__c, TotalPrice, WorkOrder.WorkOrderNumber, Work_Order_No__c,
                     Duration, ListPrice, Discount, WorkOrderId, Parent_WOLI__c, AssetId
            FROM WorkOrderLineItem
            WHERE Parent_WOLI__c = false AND WorkOrderId = :woId
            WITH SECURITY_ENFORCED
        ];}
}

 
  • September 14, 2022
  • Like
  • 0