0

I am trying to add CreatedBy.Name for the case record on the LWC Component used as a case hierarchy but no data is coming in.

Can someone please suggest a way

JS-

import { LightningElement, track, wire,api } from 'lwc';
import fetchCases from '@salesforce/apex/casecontrol.getcaseList';

export default class CasetreeHierarchy extends LightningElement {
    @api recordId;
    cases;
    error;
    @api searchKey;
    @track gridColumns = [  {
            
        fieldName : "CaseNumberurl",
        label: "Case Number",
        type: 'url',
        typeAttributes: {label: { fieldName: 'CaseNumber' }, 
        target: '_blank'}
    },
    {
        type: 'text',
        fieldName: 'Origin',
        label: 'Origin'
    },
    {
        type: 'text',
        fieldName: 'Subject',
        label: 'Subject'
    },
    {
        
        fieldName: 'Createdby.check',
        label: 'Created by'
    }
    ];
    @track gridData;

    @wire(fetchCases,{ caseid: '$recordId'})
    casetreedata({ error, data }) {

        console.log('Inside wire' );
        if ( data ) {
            this.data =  data.map(
                record => Object.assign(
                    { "Createdby.check": (record.Createdby != null && record.Createdby != '') ? record.Createdby.Name: '' },
                    record
                    )
                    );
            
           
            var tempData = JSON.parse( JSON.stringify( data ) );

                    
            for ( var i = 0; i < tempData.length; i++ ) {

                tempData[ i ]._children = tempData[ i ][ 'Cases' ];
                delete tempData[ i ].Cases;
                this.cases=tempData;

                console.log(this.cases);
        
            }

            
            this.cases.forEach(item => {
                item['CaseNumberurl'] = '/' +item['Id'];
                if(item && item._children){
                    item._children = item._children.map(child => {
                        child.CaseNumberurl = '/' +child['Id'];
                        return child;
                    });
                }
            }) 
            
           
            

        } else if ( error ) {
         this.error=error;

        }
    }

}

HTML -

<template>

    <div class=”slds-p-around_medium”>

      
        <lightning-tree-grid columns = {gridColumns}
                                data = {cases}
                                key-field = 'Id'
                                hide-checkbox-column = true>
        </lightning-tree-grid>
</div></template>

Apex-

@AuraEnabled(cacheable=true)
public static List<case>getcaseList(id caseid)
{
List<case> caseList = [Select id , subject ,casenumber,origin,createdby.name,(select id ,casenumber,origin, subject ,createdby.name from cases ) from case where parentid=:caseid];
system.debug('test'+caseList);
    return caseList;
}

1 Answer 1

1

You have to manipulate the data

{
   type: 'text',
   fieldName: 'ownerName',
   label: 'Subject'
}

add column name as ownerName

this.tableData = data.map(item=>{
    let ownerName = item.createdby.name != undefined ? item.createdby.name:" "
    return {...item, 
        "ownerName":ownerName,
    }
})

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .