I'm in the midst of creating a lightning web component to visualise salesforce records in the concept of a timeline. I've managed to create my timeline component, styling etc, and retrieve the data using salesforce's fairly recently released API. I've provided a link below, for further information. I'm fairly new to JavaScript so forgive me if there is any poor mistakes.
The problem comes from when I retrieve the data, and attempt to split the records, into different collections based on a fields certain value, it yields no result. I use for:each in my HTML to call my collections and no records are displayed.
I believe the problem lies in the for loop that appends the data to the collections, but I'm not sure. I've changed data[x]
to this.records[x]
and it yields the same results. I'd appreciate any pointers, and welcome any constructive criticisms.
Note that when I use the records collection provided by the api the records are displayed.
Timeline.js
import { LightningElement,api, wire, track} from 'lwc';
import { getRelatedListRecords } from 'lightning/uiRelatedListApi';
export default class timeline extends LightningElement {
@api recordId;
@track CompletedTasks = [];
@track InProgressTasks = [];
@track OverdueTasks = [];
error;
records;
@wire(getRelatedListRecords, {
parentRecordId: '$recordId',
relatedListId: 'Tasks__r',
fields: ['Task__c.Id','Task__c.Name', 'Task__c.Estimated_Completion_Date__c', 'Task__c.Completion_Status__c'],
sortBy: ['Task__c.Estimated_Completion_Date__c'],
})listInfo({ error, data }) {
if (data) {
this.records = data.records;
this.error = undefined;
for (let x = 0; x < data.length; x++) {
if (data[x].Completion_Status__c === "Completed") {
this.CompletedTasks.append(data[x]);
} else if (data[x].Completion_Status__c === "In Progress") {
this.InProgressTasks.append(data[x]);
} else if (data[x].Completion_Status__c === "Overdue") {
this.OverdueTasks.append(data[x]);
}
}
} else if (error) {
this.error = error;
this.records = undefined;
}
}
Timeline.html
<lightning-tab label="All Tasks" value="All Tasks" title = "All Tasks">
<div style="overflow-x: scroll; height:130px;">
<div class="tasks-container">
<template for:each={CompletedTasks} for:item="rec">
<div key={rec.fields.Id.value}>
<template if:true={CompletedTasks}>
<div class="task-card">
<ul class="slds-has-dividers_around-space" draggable="true">
<li class="slds-item">
<article class="slds-tile slds-tile_board">
<h3 class="slds-tile__title slds-truncate" title="Journey Name">
<p style = "font-weight: 600;">Web Development Onboarding</p>
</h3>
<div class="slds-tile__detail">
<div class="slds-text-heading_small">
<a>
{rec.fields.Name.value}
</a>
</div>
<p class="slds-truncate" title="Esimated Completion Date:">Esimated Completion Date:</p>
<div class = "statusdate">
<p class="slds-truncate" title="Date" style = "width: 200px;">{rec.fields.Estimated_Completion_Date__c.value}</p>
<div class = "statusbuttoncomplete">
<span class="slds-badge slds-theme_success">{rec.fields.Completion_Status__c.value }</span>
</div>
</div>
</div>
</article>
</li>
</ul>
</div>
</template>
</div>
</template>
</div>
</div>
</lightning-tab>