function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Banwari KevatBanwari Kevat 

Unable to get property 'config' of undefined or null reference

I am getting the  error at following line
 User-added image
component.set("v.items",items);

Controller code: 
({
    doInit : function(component, event, helper){
        var getItemsAction = component.get("c.getItems");
        getItemsAction.setCallback(scope, function(response){
            var state = response.getState();
            if(state=="SUCCESS"){
                var items = response.getReturnValue();
                component.set("v.items",items);
            }
            
        });
        $A.enqueueAction(getItemsAction);
        
    },
    clickCreateItem : function(component, event, helper) {
           helper.createItem(component);
    }
})

and Helper
({
    createItem : function(component) {
        var newItem = component.get("v.newItem");
        var newItem1 = JSON.parse(JSON.stringify(newItem));
        var items = component.get("v.items");
        items.push(newItem1);
        component.set("v.items",items);
        component.set("v.newItem", {'sobjectType':'Camping_Item__c','Name':'','Quantity__c':0,'Price__c':0,'Packed__c':false});
        /*var saveItemAction = component.get("c.saveItem");
        saveItemAction.setParams({campingItem:newItem1});
        saveItemAction.setCallback(scope, function(response){
            var state = response.getState(); alert(state);
            if(state=="SUCCESS"){
            }
        });
        $A.enqueueAction(saveItemAction); */
    }
})

coponent code
<aura:component controller="CampingListController">
    <aura:attribute name="newItem" Type="Camping_Item__c" default="{'sObjectType':'Camping_Item__c','Quantity__c':0,'Price__c':0,'Name':'test'}"/>
    <aura:attribute name="items" Type="Camping_Item__c[]" />
    <aura:handler name="init" action="{!c.doInit}" value="{!this}" />
    
    <ol>
        <li>Bug Spray</li>
        <li>Bear Repellant</li>
        <li>Goat Food</li>
    </ol>
    
    <form class="slds-form--stacked" aura:id="campingform">
        <lightning:input  aura:id="newItemName" label="Camping Item Name" value="{!v.newItem.Name}" />
        <lightning:input aura:id="newItemPrice" label="Price" value="{!v.newItem.Price__c}" Type="number"
                         namename="campingPrice"
                         min="0.1"
                         formatter="currency"
                         step="0.1"
                         messageWhenRangeUnderflow="Enter an Price that's at least 0.1."/>
        <lightning:input aura:id="newItemQuantity" label="Quantity" type="Integer" value="{!v.newItem.Quantity__c}" min="1"/>
        <lightning:input aura:id="newItemPacked" label ="Packed" checked="{!v.newItem.Packed__c}" type="checkbox"/>
        <lightning:button label="Submit" onclick="{! c.clickCreateItem}" />
    </form>
    
    <div class ="slds-card slds-p-top--meduim">
        <header class ="slds-card__header">
            <h3 class = "slds-text-heading--small">Items</h3>
        </header>
        <section class ="slds-card__body">
            <div id="list" class = "row">
                <aura:iteration items="{!v.items}" var="itemVar">
                    <c:campingListItem item="{!itemVar}"/>
                </aura:iteration>
            </div>
        </section>
    </div>
</aura:component>



Please help me on the issue.

 
Rohit Kumar SainiRohit Kumar Saini
Hi Banwari,

items attribute in your component doesn't have a default value so first time when you are using below line, it is returning undefined or null:

var items = component.get("v.items"); ( line #5 in helper)

You are pushing newItem1 to items which will not work if items is undefined or null. Adding below lines between 5 and 6 lines in your Helper should fix this.
 
if(items==undefined || items==null){
  items=[];
}

Thanks.