+ Start a Discussion
Jacob Elliott 8Jacob Elliott 8 

LWC- Sort Records Returned By Wire Service To Be Used By Child Components

Hello All, I'm trying to create a parent component that uses wire service to grab task records and then sorts them into two maps(?) to be consumed by child components. I need them sorted by Status = Completed or Status != Completed.

I'm having trouble figuring out how to iterate over the returned records.

Any help would be greatly appreciated!

Controller
public with sharing class ATLController {
    @AuraEnabled(Cacheable=true)
    public static List<Task> getTasks(String recordId) {
        return [SELECT Id, Subject, TaskSubtype, ActivityDate FROM Task WHERE WhatId = :recordId];
    }
}
JS
import { LightningElement, api, wire } from 'lwc';

export default class AtlBase extends LightningElement {
    @api recordId;

    completedTaskList = [];
    upcomingTaskList = [];

    @wire(getTasks, {recordId:'$recordId'}) 
        tasks; 

        for(let task in tasks){
            if(task.Status === 'Completed'){
                completedTaskList.push(task);
            } else if(task.Status != 'Completed'){
                upcomingTaskList.push(task);
            }
        }
}


 
Best Answer chosen by Jacob Elliott 8
MagulanDuraipandianMagulanDuraipandian
Check this - https://www.infallibletechie.com/2020/03/how-to-iterate-over-records-returned-by.html