You need to sign in to do that
Don't have an account?
Shuhbam Sinha
How to put null check in JS of LWC
Hello Everyone,
I am creating a table to show list of related records of case using LWC.The columns that I am showing is lookup field so was getting IDs of that fields but I am able to convert it to Name . Now challenge is if any record does not have value of that look up field then full table is not rendering. I need to check in JS for that field while converting it to ID to name if it is null or not. If it is null then skip the particular field value. Please find the code below . I have highlighted the part where I need to put null check.
I am creating a table to show list of related records of case using LWC.The columns that I am showing is lookup field so was getting IDs of that fields but I am able to convert it to Name . Now challenge is if any record does not have value of that look up field then full table is not rendering. I need to check in JS for that field while converting it to ID to name if it is null or not. If it is null then skip the particular field value. Please find the code below . I have highlighted the part where I need to put null check.
@wire(getCaseApprovalRE, {caseId: '$recordId'}) wiredAccounts(result) { this.wiredAccountsResult = result; if (result.data) { this.recordNumber = result.data.length; return{...row, Approver1__c: row.Approver1__r.Name, Approver2__c:row.Approver2__r.Name , Approver_3__c:row.Approver_3__r.Name, Step_2_Approver_1__c:row.Step_2_Approver_1__r.Name, // I need to put if condition here if the below field is null or not Step_2_Approver_2__c:row.Step_2_Approver_2__r.Name, } }) } else if (result.error) { this.error = result.error; this.accData = undefined; } }Please help me on this .Thanks in advance.
Hello,
let street = '' // assign a default value is a good practice, we use an empty string here
if(getFieldValue(this.contactRecord, STREET_FIELD)) { street = getFieldValue(this.contactRecord, STREET_FIELD) //if it is not null reassign }
Or you can do it in one line
let street = getFieldValue(this.contactRecord, STREET_FIELD) ?getFieldValue(this.contactRecord, STREET_FIELD) : ''
Thanks, https://www.cuims.net/