Rock, Rock, Rockaway... Uncaught TypeError: Cannot read property 'length' of undefined

Who doesn’t like an Uncaught TypeError after installing a new package?


Page XML? Some idea of what that page is trying to do? Give us something to go on here!

Hey J.,

Yup, probably related to a page XML/model definition.  Experiencing this across two Orgs and different pages. Unfortunately, the stack trace doesn’t give me much to go on, otherwise, I would troubleshoot myself.

I’ve given you login access to one org.  What is the proper channel to provide more context to you?

Thanks, Irvin

Shoot an email to support@skuid.com with the Org ID, the name of the page that’s giving you problems, any steps to replicate (sounds like previewing the page does it), and anything else you think would be important for us to know. Thanks!

Cool, will do.  Thanks.

I see the issue, and it’s a bug in Rockaway. It has to do with model subquery conditions that have no sub conditions. Basically, if you don’t have any, you’ll get the error. Adding a sub condition that always returns true (e.g. Id != null) is a workaround. I’ve replicated the issue in my dev org, and logged the bug. The fix looks pretty easy, so I think we can get this turned around pretty quickly. Thanks for helping find issues like this!

Edit: This issue has been resolved in Rockaway Point Release - Iteration 1 (and subsequent releases), available from the Skuid Releases page.

No worries and thanks for the quick turnaround.  I’ll spend more time with the release soon.  Thanks again.

Irvin - I’m experiencing a similar problem from this bug. Would you be willing to paste a sample of what you did to resolve it?

Hi Griffin, Since I only encountered this in a Sandbox, I have not implemented the workaround as J suggested.  Instead, I will wait for the patch.

Workaround: Adding a sub condition that always returns true (e.g. Id != null) is a workaround. 

Irvin - you are a wise and patient soul. I wanted the performance boost too much, I believe. Thanks for the lightning quick response!

J - can you should me an example of what that code would look like?

I took a look at your other post, and I’m pretty sure that it’s not the same issue as Irvin’s. Your issue is in your snippet. Irvin’s issue is completely a declarative Skuid thing: the error is surfacing from within Skuid code. See this tutorial for our official writeup on how those are specified in the Skuid Composer. I’ll check in on your other post here next, but I wanted to close the loop here first.

I’m having the same issue.  Uncaught TypeError: Cannot read property ‘getSelectedItems’ of undefined.  Has this been resolved?  Thanks!

I think this may be the model that’s causing issues for me. I have a sub-query where the sub-condition is a filter. This is the model that’s referenced in the “getSelectedItems” part of my snippet.

Any suggestions for how I should update this model so I don’t get the error?

Elissa,

Irvin’s issue had to do with subquery conditions that had no subconditions, and it was resolved in Rockaway - Iteration 1. He was getting…

Uncaught TypeError: Cannot read property 'length' of undefined 

…but you are getting…

Uncaught TypeError: Cannot read property 'getSelectedItems' of undefined

Do you have any custom JavaScript on the page? It’s just a guess, but we’ve seen a couple reports of snippets that needed to be updated for Rockaway and the symptom was this same error message.

Yup, and it looks like the “getSelectedItems()” function is at fault.  

Here’s my snippet: 

var params = arguments[0];var $ = skuid.$;
var records = skuid.$.map(arguments[0].list.getSelectedItems(),function(item){ 
    return item.row.Id; 
    });
    
var models = skuid.model.map();
var cases = models.CasesToCover;
var User = models.CoveringUser;
var newTeamMembers = models.NewCoverageTeam;

    for(var n in records){
        var row = cases.getRowById(records[n]);
    
        if(row !== false){
            var newRow = newTeamMembers.createRow({
                additionalConditions: [
                    { field: ‘ParentId’, value: row.Id },
                    { field: ‘MemberId’, value: User.getFieldValue(User.getFirstRow(),“CoverageUser”) },
                    { field: ‘TeamRoleId’, value: ‘0B7E0000000PBOT’ } ]
            });
        }
    }

newTeamMembers.save();



Do I just need to update this part? 

var records = skuid.$.map(arguments[0].list.getSelectedItems(),function(item){ 
    return item.row.Id; 
    });

Unless, you’ve got another snippet on that page that’s calling getSelectedItems that is the culprit, that is where it’s breaking down (arguments[0].list is undefined). The advice that JD gave at the end of that other post should work for you.

Still having trouble.  I’ve got this now.  Can you help me figure out where I might be going wrong?  (I know I still have the ‘getSelectedItems’ piece in here, but if I understand the last post correctly, it should be okay so long as I call the table by unique ID first.)


var params = arguments[0];var $ = skuid.$;

    
var table = skuid.$(‘sk-v30sc-347’),
   list,
   items;
if (table.length) {
   list = table.data(‘object’).list;
   items = list.getSelectedItems();
}  
    
    
var models = skuid.model.map();
var cases = models.CasesToCover;
var User = models.CoveringUser;
var newTeamMembers = models.NewCoverageTeam;

    for(var n in items){
        var row = cases.getRowById(items[n]);
    
        if(row !== false){
            var newRow = newTeamMembers.createRow({
                additionalConditions: [
                    { field: ‘ParentId’, value: row.Id },
                    { field: ‘MemberId’, value: User.getFieldValue(User.getFirstRow(),“CoverageUser”) },
                    { field: ‘TeamRoleId’, value: ‘0B7E0000000PBOT’ } ]
            });
        }
    }

newTeamMembers.save();

I think you’re really close. Check JD’s response again:

table.element.data(‘object’).list

Still no luck.  I’m trying a combo of JD’s and Zach’s earlier response.  Here’s what I have.  I don’t think that the function list.getSelectedItems() is actually getting anything, as when I try to log rows in the console nothing appears. 



var params = arguments[0];
var $ = skuid.$;
    
    
var models = skuid.model.map();
var cases = models.CasesToCover;
var User = models.CoveringUser;
var newTeamMembers = models.NewCoverageTeam;


var table = skuid.$(‘sk-v30sc-347’),
   list,
   items;
   
if (table.length) {
   list = table.element.data(‘object’).list;
   items = list.getSelectedItems();
}  

    for(var n in items){
        var row = cases.getRowById(items[n]);
            console.log('Row: ’ + row);
            console.log('Row Id: ’ + row.Id);
    
        if(row !== false){
            var newRow = newTeamMembers.createRow({
                additionalConditions: [
                    { field: ‘ParentId’, value: row.Id },
                    { field: ‘MemberId’, value: User.getFieldValue(User.getFirstRow(),“CoverageUser”) },
                    { field: ‘TeamRoleId’, value: ‘0B7E0000000PBOT’ } ]
            });
        }
    }

newTeamMembers.save();