CountDictionary is undefined

When migrating custom solutions from an earlier version of SharePoint to SharePoint 2016 you might run into this javascript error.

Most likely when you try to count how many items are selected in a listview.

The code of the origional function (which probably still exists, but is now scoped to that SharePoint functionality within the javascript file (inplview.js)) looked like this:

function CountDictionary(b) {
var a = 0, c;
for (c in b)
a++;
return a
}

We see in 2016 that this is used to retrieve the number of currently selected items:

ListModule.Util.countSelectedItems(this.ctx)

So you could use that instead.

Advertisements

5 thoughts on “CountDictionary is undefined

  1. Anonymous January 20, 2017 at 11:40 Reply

    Thanks a lot, saved time,Basically where (which .js file )this function reside

  2. Anonymous January 20, 2017 at 12:03 Reply

    In Previous version in which file CountDictionary exist and can we refer inplview.js in SP16 directly instead of in custom java script.Please suggest

    • CarolinePoint January 24, 2017 at 14:49 Reply

      The file still exists and should be loaded for a listview. However it no longer contains this function. You can find a readable version here {2016SiteUrl}/_layouts/15/inplview.debug.js.

      You can also see it’s using this function now:
      ListModule.Util.countSelectedItems(this.ctx)
      So you could use that instead. I’ve updated the origional post as well.

  3. Anonymous February 20, 2017 at 15:45 Reply

    The function has been moved to /_layouts/15/core.js

    • CarolinePoint February 20, 2017 at 15:53 Reply

      I see, though it’s name is changed to _CountDictionary (with an extra leading underscore).

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: