0

Receiving below errors from javascript once i click 'view more' on related list

Access Check Failed! AttributeSet.get(): attribute 'loadMoreStatus' of component 'markup://c:RelatedListWindow {6525:0}' is not visible to 'markup://c:RelatedListWindow {6525:0}'.

Access Check Failed! AttributeSet.get(): attribute 'Infiniteloading' of component 'markup://c:RelatedListWindow {6525:0}' is not visible to 'markup://c:RelatedListWindow {6525:0}'.

Controller script

({
init : function(cmp, event, helper) {
    $A.util.removeClass(cmp.find("spinner"), 'slds-hide');
    helper.setInit(cmp,event,helper);

    setInterval(function() {
        cmp.set("v.updatedAgo",cmp.get("v.updatedAgo")+1);
    },60000);
},
refresh : function(cmp,event,helper){
    helper.setInit(cmp,event,helper);
},
loadMoreData: function (cmp, event, helper) {

    var promiseData;

    event.getSource().set("v.isLoading", true);
    cmp.set('v.loadMoreStatus', 'Loading');

    promiseData = helper.loadMore(cmp,helper,cmp.get("v.data").length);

    promiseData.then($A.getCallback(function (data) {
        if (cmp.get('v.data').length >= cmp.get('v.maxCount')) {
            cmp.set('v.enableInfiniteLoading', false);
            cmp.set('v.loadMoreStatus', 'No more data to load');
        } else {
            var currentData = cmp.get('v.data');
            var newData = currentData.concat(data);
            cmp.set('v.data', newData);
            cmp.set('v.loadMoreStatus', '');
        }
        event.getSource().set("v.isLoading", false);
    }));
},
updateColumnSorting:function(component, event, helper){
    var sortName = event.getParam("fieldName");
    var sortDirection = event.getParam("sortDirection");
    component.set("v.sortedBy", sortName);
    component.set("v.sortedDirection", sortDirection);
    if (sortName == "linkName") {sortName = "Name" ;}               //if sort by name
    component.set("v.sortOrder",sortName + " " + sortDirection);
    for (var field of component.get('v.columns')){
        if (field.fieldName == sortName){
            component.set("v.sortOrderLabel", field.label);
            break;
        }
    }
    console.log("SortOrder: "+component.get("v.sortOrder"));

    var promiseData = helper.loadMore(component,helper,0);
    promiseData.then(function(results) {
        component.set('v.data', results);
    });
},
newRecord:function(cmp,event,helper){
    cmp.set('v.showRTModal',true);
},
navObjHome:function(cmp,event,helper){
    var navService = cmp.find("navService");
    var pageReference =        {    
        "type": "standard__objectPage",
        attributes: {
            objectApiName: "Account",
            actionName: "list"
        },
        state: {
            filterName: "Recent"
        }
    };
    navService.navigate(pageReference);
},
navRecord:function(cmp,event,helper){
    var navService = cmp.find("navService");
    var pageReference =        {    
        "type": "standard__recordPage",
        attributes: {
            recordId: cmp.get("v.recordId"),
            objectApiName: cmp.get("v.parentObjAPI"),
            actionName: "view"
        },
        state: {
            filterName: "Recent"
        }
    };
    navService.navigate(pageReference);
},
handleRowAction: function (cmp, event, helper) {
    var action = event.getParam('action');
    var row = event.getParam('row');
    switch (action.name) {
        case 'editRecord':
            helper.editRecord(row['Id']);
            break;
        case 'viewRecord':
            helper.viewRecord(row['Id']);
            break;
    }
}

})

Helper script

({
setInit : function(cmp,event,helper){
    var object = cmp.get("v.pageReference").state.c__object;
    var objectLabel = cmp.get("v.pageReference").state.c__objectLabel ;
    var iconName = cmp.get("v.pageReference").state.c__iconName;
    var fields = cmp.get("v.pageReference").state.c__fields ;
    var relationship = cmp.get("v.pageReference").state.c__relationship;
    var sortOrder = cmp.get("v.pageReference").state.c__sortOrder;
    var conditions = cmp.get("v.pageReference").state.c__conditions;
    var recordId = cmp.get("v.pageReference").state.c__recordId;
    var fields = cmp.get("v.pageReference").state.c__fields;
    var maxCount = cmp.get("v.pageReference").state.c__maxCount;
    var actionList = cmp.get("v.pageReference").state.c__actionList;

    cmp.set("v.object",object);
    cmp.set("v.objectLabel",objectLabel);
    cmp.set("v.iconName",iconName);
    cmp.set("v.fields",fields);
    cmp.set("v.relationship",relationship);
    cmp.set("v.sortOrder",sortOrder);
    cmp.set("v.conditions",conditions);
    cmp.set("v.recordId",recordId);
    cmp.set("v.fields",fields);
    cmp.set("v.maxCount",maxCount);
    cmp.set("v.actionList",actionList);

    cmp.set('v.actionNew',cmp.get('v.actionList') ? cmp.get('v.actionList').includes('new') : false);

    cmp.set("v.updatedAgo",0);

    helper.getParentNames(cmp,recordId);

    helper.fetchColumns(cmp,event,helper, recordId, fields, object);

    var promiseData = helper.loadMore(cmp,helper,0);
    promiseData.then(function(results) {
        cmp.set('v.data', results);
    });

    helper.setTabLabelIcon(cmp,object);  
},
fetchData : function(cmp, recordId, fields, relatedObjectName, sortOrder, conditions, relationship,limit, offset) {
    var action = cmp.get("c.getRecords");
    action.setParams({
        "recId": recordId,
        "fields": fields,
        "relatedObjectName": relatedObjectName, 
        "sortOrder": sortOrder, 
        "conditions": conditions, 
        "relationship": relationship,
        "recordLimit":limit.toString(),
        "offset": offset.toString()
    });

    var promisedata = new Promise(function(resolve, reject) {
        action.setCallback(this, $A.getCallback(function (response) {
            var state = response.getState();
            if (state === "SUCCESS") {
                var data = response.getReturnValue();
                console.log('DATA Original: ' + JSON.stringify(data));

                data.forEach(function(record){
                    for (var field of cmp.get('v.columns')){
                        if (field.typeAttributes && field.typeAttributes.relationship){
                            if (record[field.typeAttributes.relationship]) {
                                record[field.typeAttributes.relationship+"_Id"] = "/" +record[field.typeAttributes.relationship]['Id'];
                                record[field.typeAttributes.relationship+"_Name"] = record[field.typeAttributes.relationship]['Name'];
                            }
                        } else if (field.cellAttributes){
                            if (record[field.fieldName]){
                                record[field.fieldName+"_chk"] = 'utility:check';
                            }
                        } else if (field.type == 'DATETIME'){
                            var d = new Date(record[field.fieldName]);
                            record[field.fieldName] = d.toLocaleString();
                        } else if (field.type == 'TEXTAREA'){
                            record[field.fieldName] = record[field.fieldName].split('\n')[0];
                        }
                    }
                    record.linkName = '/'+ record.Id;
                    record.urlName = record.Name;

                });

                console.log('DATA: ' + JSON.stringify(data));
                resolve(data);
            } else if (state === "ERROR") {
                var errors = response.getError();
                console.error(errors);
                return null;
            }
            $A.util.addClass(cmp.find("spinner"), 'slds-hide');
        }));
    });

    $A.enqueueAction(action);
    return promisedata;
},
loadMore:function(cmp,helper,offset){
    var object = cmp.get("v.object");
    var fields = cmp.get("v.fields");    
    var relationship = cmp.get("v.relationship");
    var sortOrder = cmp.get("v.sortOrder");
    var conditions = cmp.get("v.conditions");
    var recordId = cmp.get("v.recordId");
    var rowsToLoad = cmp.get('v.rowsToLoad');

    return helper.fetchData(cmp, recordId, fields, object, sortOrder, conditions, relationship,rowsToLoad,offset);
},
setTabLabelIcon:function(cmp){
    //set title and heading
    var workspaceAPI = cmp.find("workspace");
    workspaceAPI.getFocusedTabInfo().then(function(response) {
        console.log(response);
        for (var i of response.subtabs){
            if (i.pageReference.state.object == cmp.get("v.pageReference").state.object){
                var focusedTabId = i.tabId;
                workspaceAPI.setTabLabel({
                    tabId: focusedTabId,
                    label: i.pageReference.state.objectLabel
                });
                workspaceAPI.setTabIcon({
                    tabId: focusedTabId,
                    icon: cmp.get("v.iconName"),
                    iconAlt: i.pageReference.state.objectLabel
                });

            }
        }
    }).catch(function(error) {
        console.log(error);
    });
},
getParentNames:function(cmp,recordId){
    //set scrumbread
    var action = cmp.get("c.getParentObjectName");
    action.setParams({
        "recordId": recordId
    });
    action.setCallback(this, $A.getCallback(function (response) {
        var state = response.getState();
        if (state === "SUCCESS") {
            var names = response.getReturnValue();
            cmp.set('v.parentObjLabel', names['parentObjLabel']);
            cmp.set('v.parentObjAPI', names['parentObjAPI']);
            cmp.set('v.parentRecName', names['parentRecName']);
            console.log('parentNames: ' + names);
        } else if (state === "ERROR") {
            var errors = response.getError();
            console.error(errors);
        }
    }));
    $A.enqueueAction(action);
},    
fetchColumns : function(cmp,evt,hlp, recordId, fields, relatedObjectName) {
    var tableAction = hlp.getTableActions(cmp);
    var action = cmp.get("c.getColumns");
    action.setParams({
        "recId": recordId,
        "fields": fields,
        "relatedObjectName": relatedObjectName
    });
    action.setCallback(this, $A.getCallback(function (response) {
        var state = response.getState();
        if (state === "SUCCESS") {
            var columns = response.getReturnValue();
            tableAction.length != 0 ? columns.push({ type: 'action', typeAttributes: { rowActions: tableAction } }) : '';
            cmp.set('v.columns', columns);
            console.log('COLUMNS: ' + JSON.stringify(columns));
        } else if (state === "ERROR") {
            var errors = response.getError();
            console.error(errors);
        }
    }));
    $A.enqueueAction(action);
},
getTableActions:function(cmp){
    var actionListMap = {
        'view' : { label: 'View', name: 'viewRecord' },
        'edit' : { label: 'Edit', name: 'editRecord' }
    };
    var tableAction = [];
    var actionLists = cmp.get('v.actionList') ? cmp.get('v.actionList').split(';') : [];
    for (var i = 0; i<actionLists.length;i++){
        actionListMap[actionLists[i]] ? tableAction.push(actionListMap[actionLists[i]]) : '';
    }
    return tableAction;
},
editRecord:function(recordId){
    var editRecordEvent = $A.get("e.force:editRecord");
    editRecordEvent.setParams({
        "recordId": recordId
    });
    editRecordEvent.fire();
},
viewRecord:function(recordId){
    var editRecordEvent = $A.get("e.force:navigateToSObject");
    editRecordEvent.setParams({
        "recordId": recordId
    });
    editRecordEvent.fire();
}

})

Component

<aura:component implements='lightning:isUrlAddressable,flexipage:availableForRecordHome' access='global' controller='SummaryTableController'>
<!--crumbread parameters-->
<aura:attribute name="parentObjLabel" type="String"/>
<aura:attribute name="parentObjAPI" type="String"/>
<aura:attribute name="parentRecName" type="String"/>

<aura:attribute name="updatedAgo" type="Integer" default = '0'/>

<aura:attribute name="object" type="String"/>
<aura:attribute name="objectLabel" type="String"/>
<aura:attribute name="fields" type="String"/>
<aura:attribute name="sortOrder" type="String"/>
<aura:attribute name="sortOrderLabel" type="String"/>
<aura:attribute name="relationship" type="String"/>
<aura:attribute name="conditions" type="String"/>
<aura:attribute name="iconName" type="String"/>
<aura:attribute name="rowsToLoad" type="Integer" default="50"/>

<!-- action lists -->
<aura:attribute name='actionList' type='String' default='' />
<aura:attribute name='actionNew' type='Boolean' default='true'/>

<aura:attribute name="maxCount" type="Integer" default="50"/>
<aura:attribute name="loadMoreOffset" type="Integer" default="20"/>
<aura:attribute name="enableInfiniteLoading" type="Boolean" default='true'/>
<aura:attribute name="sortedBy" type="String" />
<aura:attribute name="sortedDirection" type="Boolean" default="true" />

<aura:attribute name="data" type="Object"/>
<aura:attribute name="columns" type="Object" />
<aura:attribute name="recordId" type="String" />

<aura:attribute name="showRTModal" type="Boolean" default='false'/>
<lightning:navigation aura:id="navService"/>

<aura:handler name="init" value="{! this}" action="{! c.init }"/>
<aura:handler name="change" value="{!v.pageReference}" action="{!c.init}" />

<lightning:workspaceAPI aura:id="workspace" />    

<lightning:spinner aura:id="spinner" alternativeText="Searching" size="medium" variant="brand" class="slds-hide"/>
<div class='slds-page-header--object-home slds-page-header_joined slds-page-header_bleed slds-page-header slds-shrink-none test-headerRegion forceListViewManagerHeader'>
    <div class='slds-grid'>
        <div class='slds-col slds-has-flexi-truncate'>
            <lightning:breadcrumbs>
                <lightning:breadcrumb label="{!v.parentObjLabel}" onclick="{!c.navObjHome}"/>
                <lightning:breadcrumb label="{!v.parentRecName}" onclick="{!c.navRecord}"/>
            </lightning:breadcrumbs>
            <h1 class='slds-page-header__title slds-truncate'>{!v.objectLabel}</h1>
        </div>

        <div class='slds-col slds-no-flex slds-grid slds-align-top slds-p-bottom--xx-small test-lvmForceActionsContainer'>
            <aura:if isTrue = '{!v.actionNew}'>
                <lightning:button label="New" title="New" onclick="{! c.newRecord }"/>
            </aura:if>
        </div>
    </div>

    <div class='slds-grid'>
        <div class='slds-col slds-align-bottom'>
            <p>{!v.data.length}{!v.InfiniteLoading == true ? '+ ' : ' '}item{!v.data.length>1?'s':''} • Sorted by {!v.sortOrderLabel} • Updated {!v.updatedAgo>0 ? (v.updatedAgo >1 ? v.updatedAgo+' minutes ago' : 'a minute ago') : 'a few seconds ago' }</p>
        </div>
        <div class='slds-col slds-no-flex slds-grid slds-align-bottom'>
            <lightning:buttonIcon iconName="utility:refresh" variant="border-filled" alternativeText="Refresh" onclick='{!c.refresh}' />
        </div>
    </div>
</div>
<div style="height: 100%">
    <lightning:datatable
                         data="{! v.data}"
                         columns="{! v.columns}"
                         keyField="id"
                         showRowNumberColumn="true"
                         loadMoreOffset="{! v.loadMoreOffset }"
                         enableInfiniteLoading="{! v.enableInfiniteLoading }"
                         onloadmore="{! c.loadMoreData }"
                         hideCheckboxColumn = "true"

                         sortedBy="{! v.sortedBy }"
                         sortedDirection="{! v.sortedDirection }"
                         defaultSortDirection="desc"
                         onsort="{! c.updateColumnSorting }"
                         onrowaction="{! c.handleRowAction }"
                         />

</div>
{! v.loadMoreStatus }

<c:RecordTypeModal objectAPIName='{!v.object}' objectName='{!v.objectLabel}' show='{!v.showRTModal}' relationship='{!v.relationship}' recordId = '{!v.recordId}'/>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.