You need to sign in to do that
Don't have an account?
Pavushetti Abhilash 3
display accountname in lwc datatable otherwise display remaining fields
Hi everyone.
I got a small issue that when I dont give the account name my entire component is getting error. Saying that Name undefined. When I gave the account name the TABLE is displaying, when i left empty in account field entire comp getting error. Atleast the table should display with empty field and displaying other fields(what user given input). Empty field should not effect the other fields displaying.
1. So here I have 4 fields two fields are mandatory. Other two fields are optional(MMID__r, STOCKING_ID__r)
2. When user not entered optional fields atleat remaining fields should display. But in my comp entire table not displaying showing error message. Error msg: [Cannot read properties of undefined (reading 'Name')]
Please refer JS
@wire(getSelectedCaseLineItems, {caseid: '$recordId'})
caseLineItems({ error, data }){
if(data)
{
console.log(data);
this.caseLineItems = data.map(
record => Object.assign(
{"Sold_To__r.Name": record.Sold_To__r.Name, "Ship_To__r.Name": record.Ship_To__r.Name,
"MMID__r.Name": record.MMID__r.Name == null ? "": record.MMID__r.Name,
"Stocking_ID__r.Name": record.Stocking_ID__r.Name == null ? "" : record.Stocking_ID__r.Name
},
record
)
);
}
else if(error){
this.error = error;
this.caseLineItems = undefined;
}
}
-----------------------------------------------------------------------------
In order to display remaining fields( which user given input) I used if-else condition.
@wire(getSelectedCaseLineItems, {caseid: '$recordId'})
caseLineItems({ error, data }){
if(data)
{
console.log(data);
if(data.MMID__r.Name != null && data.Stocking_ID__r.Name != null){
this.caseLineItems = data.map(
record => Object.assign(
{"Sold_To__r.Name": record.Sold_To__r.Name, "Ship_To__r.Name": record.Ship_To__r.Name,
"MMID__r.Name": record.MMID__r.Name, "Stocking_ID__r.Name": record.Stocking_ID__r.Name
},
record
)
);
} else {
this.caseLineItems = data.map(
record => Object.assign(
{"Sold_To__r.Name": record.Sold_To__r.Name, "Ship_To__r.Name": record.Ship_To__r.Name,
"MMID__r.Name": record.MMID__r.Name == null ? "": record.MMID__r.Name,
"Stocking_ID__r.Name": record.Stocking_ID__r.Name == null ? "" : record.Stocking_ID__r.Name
},
record
)
);
}
}
else if(error){
this.error = error;
this.caseLineItems = undefined;
}
}
----------------------------------------------------------------------
Here also same error. Its not entering if loop.
I got a small issue that when I dont give the account name my entire component is getting error. Saying that Name undefined. When I gave the account name the TABLE is displaying, when i left empty in account field entire comp getting error. Atleast the table should display with empty field and displaying other fields(what user given input). Empty field should not effect the other fields displaying.
1. So here I have 4 fields two fields are mandatory. Other two fields are optional(MMID__r, STOCKING_ID__r)
2. When user not entered optional fields atleat remaining fields should display. But in my comp entire table not displaying showing error message. Error msg: [Cannot read properties of undefined (reading 'Name')]
Please refer JS
@wire(getSelectedCaseLineItems, {caseid: '$recordId'})
caseLineItems({ error, data }){
if(data)
{
console.log(data);
this.caseLineItems = data.map(
record => Object.assign(
{"Sold_To__r.Name": record.Sold_To__r.Name, "Ship_To__r.Name": record.Ship_To__r.Name,
"MMID__r.Name": record.MMID__r.Name == null ? "": record.MMID__r.Name,
"Stocking_ID__r.Name": record.Stocking_ID__r.Name == null ? "" : record.Stocking_ID__r.Name
},
record
)
);
}
else if(error){
this.error = error;
this.caseLineItems = undefined;
}
}
-----------------------------------------------------------------------------
In order to display remaining fields( which user given input) I used if-else condition.
@wire(getSelectedCaseLineItems, {caseid: '$recordId'})
caseLineItems({ error, data }){
if(data)
{
console.log(data);
if(data.MMID__r.Name != null && data.Stocking_ID__r.Name != null){
this.caseLineItems = data.map(
record => Object.assign(
{"Sold_To__r.Name": record.Sold_To__r.Name, "Ship_To__r.Name": record.Ship_To__r.Name,
"MMID__r.Name": record.MMID__r.Name, "Stocking_ID__r.Name": record.Stocking_ID__r.Name
},
record
)
);
} else {
this.caseLineItems = data.map(
record => Object.assign(
{"Sold_To__r.Name": record.Sold_To__r.Name, "Ship_To__r.Name": record.Ship_To__r.Name,
"MMID__r.Name": record.MMID__r.Name == null ? "": record.MMID__r.Name,
"Stocking_ID__r.Name": record.Stocking_ID__r.Name == null ? "" : record.Stocking_ID__r.Name
},
record
)
);
}
}
else if(error){
this.error = error;
this.caseLineItems = undefined;
}
}
----------------------------------------------------------------------
Here also same error. Its not entering if loop.