Skip to main content

Hi everyone! I have to get the response from an API Endpoint and display them in a data table (LWC). The response look like this:

"list": [

{

"projectName": "Onnami",

"point": {

"min": 9.11,

"max": 9.18,

"default": 9.11

}

},

{

"projectName": "Sunshine INC",

"point": {

"min": 9.11,

"default": 9.11

}

}

]

I got no problem when getting the "projectName", but when I try to get the "default" key in "point". I get the error: Uncaught (in promise) TypeError: LWC component's @wire target property or method threw an error during value provisioning. Original error:

[Cannot read properties of undefined (reading 'default')].

Here is my client side controller:

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

import getSubmissionRecords from '@salesforce/apex/SubmissionController.getSubmissionRecords';

const columns = [

{ label: 'Project Name', fieldName: 'projectName' },

{ label: 'Points', fieldName: 'point', type: 'number' },

{

label: '',

fieldName: 'details',

type: 'url',

typeAttributes: {

label: {

fieldName: 'detailName'

},

target : '_blank'

}},

];

export default class PricingTab extends LightningElement {

@api recordId;

@api columnData;

@wire(getSubmissionRecords, { projectId: '$recordId' })

returnedSubmissions({data, error}) {

if(data) {

let dataRefer = [];

data.forEach((record) => {

let preparedData = {};

preparedData.projectName = record.projectName;

preparedData.point = record.point.default;

preparedData.detailName = 'Details';

preparedData.details = 'https://google.com';

dataRefer.push(preparedData);

})

this.columnData = dataRefer;

}

if(error) {

console.log(error)

}

}

}

Here is the HTML file:

<template>

<lightning-datatable key-field="Id" data={columnData} columns={columns}></lightning-datatable>

</template>

The response returns about over 500 records.

Thank you so much!​​​​​
4 respostas
  1. 13 de jun. de 2022, 06:11
    Hi Tyler,

    FIrst you need to trace record,   use  console.log('record ==>>> '+JSON.stringify(record));

    after that we will make sure about further action

     
0/9000