Essentially what I want to do is search my list of objects which are pushed using my handle products function. Once the list has been populated I need to search if the list.CardType contains "Card Present" then set a variable in my component to True. I am being shown this error, but I have done some checks and its lead me to believe my handleNext function is the problem.

Any Ideas?


Uncaught Action failed: c:AddProductsComponent$controller$handleNext [Cannot read property '0' of undefined]

<aura:attribute name="productList"  type="List"/>


handleProduct: function(cmp, evt, helper){
var ProductId = cmp.find("productType").get("v.value"); 
var ProductName = cmp.find("productType").get("v.value");
var MIDname = cmp.get("v.selectedRecord.Name");
var MIDid = cmp.get("v.selectedRecord.Id");
var cardType = cmp.get("v.cardType");
var PL = cmp.get("v.productList");
cmp.set("v.options", ProductName);
/* Creating the new product to add to the list. */
var product = {
    MID: MIDname,
    MIDid: MIDid,
    CardType: cardType,
    ProductId: ProductId,
    Name: ProductName}; 
/* Pushed the new product to the list to update the main list  */

/* Updating the product list with new product. */
cmp.set("v.productList", PL); 

 handleNext: function(cmp, evt){
     list = cmp.get("v.productList");
     for (var i = 0; i < list.length; i++) {
        if (list[i].CardType == 'Card Present') {
        cmp.set("v.showCP", true);

    cmp.set("v.showHome", false);

1 Answer 1


list[i].CardType is causing the problem, when i = 0, it's trying to dereference list[0], but list is undefined. Start by logging the value of v.productList before that loop, and working backwards from there, to see what's going on.


You must log in to answer this question.

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