SharePoint 2013 On Premises – Resolved issue “Uncaught TypeError: Cannot read property ‘apply’ of undefined” at clientContext.executeQueryAsync() – Success or Failed methods are not getting called

Hi All,

Today new issue and solution 🙂

Description: In this article I’ll explain the exception which we received on call of – clientContext.executeQueryAsync() . We are querying to list to get the details.

Background: In one of our SharePoint 2013 on premises project, we are querying to one of our list using JSOM. This problem took some time for us to solve so thought to share, may be it will save someone’s time.

Problem: We have following code to query our one of the list, following code is copied from MSDN

var siteUrl = ‘/sites/MySiteCollection’;

function retrieveListItems() {

var clientContext = new SP.ClientContext(siteUrl);

var oList = clientContext.get_web().get_lists().getByTitle(‘list name’);

var camlQuery = new SP.CamlQuery();

camlQuery.set_viewXml(‘Our Query’);

this.collListItem = oList.getItems(camlQuery);

clientContext.load(collListItem);

clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));

}

And then we have respective onQuerySucceeded() and onQueryFailed() methods. But neither success nor failure method was getting called. After looking at console following error was shown:

Uncaught TypeError: Cannot read property ‘apply’ of undefined    at Array.<anonymous> (ScriptResource.axd?d=BBrYaIMlBhMRj655qKOQMOVbx-YmqtFxf2j59Zva35Wxwn7vkasBoIuWeeglPt5a97MMi9CDlxSoi73tJ4d4sA69tV58kSh251bg-gL8SiNV54WRxmpYqwoxmeSmgqxWVH1xnNuR9gyaDVnlwVOC4si-kU8DcYF4K2VAL43wUA8QXbjH383FdEjRGUnR8EU10&t=3d6efc1f:5)    at ScriptResource.axd?d=BBrYaIMlBhMRj655qKOQMOVbx-YmqtFxf2j59Zva35Wxwn7vkasBoIuWeeglPt5a97MMi9CDlxSoi73tJ4d4sA69tV58kSh251bg-gL8SiNV54WRxmpYqwoxmeSmgqxWVH1xnNuR9gyaDVnlwVOC4si-kU8DcYF4K2VAL43wUA8QXbjH383FdEjRGUnR8EU10&t=3d6efc1f:5   

at SP.ClientRequest.$32_0 (sp.runtime.js?rev=5f2WkYJoaxlIRdwUeg4WEg%3D%3D:2)    at Array.<anonymous> (ScriptResource.axd?d=BBrYaIMlBhMRj655qKOQMOVbx-YmqtFxf2j59Zva35Wxwn7vkasBoIuWeeglPt5a97MMi9CDlxSoi73tJ4d4sA69tV58kSh251bg-gL8SiNV54WRxmpYqwoxmeSmgqxWVH1xnNuR9gyaDVnlwVOC4si-kU8DcYF4K2VAL43wUA8QXbjH383FdEjRGUnR8EU10&t=3d6efc1f:5)   

at ScriptResource.axd?d=BBrYaIMlBhMRj655qKOQMOVbx-YmqtFxf2j59Zva35Wxwn7vkasBoIuWeeglPt5a97MMi9CDlxSoi73tJ4d4sA69tV58kSh251bg-gL8SiNV54WRxmpYqwoxmeSmgqxWVH1xnNuR9gyaDVnlwVOC4si-kU8DcYF4K2VAL43wUA8QXbjH383FdEjRGUnR8EU10&t=3d6efc1f:5   

at Sys.Net.WebRequest.completed (ScriptResource.axd?d=BBrYaIMlBhMRj655qKOQMOVbx-YmqtFxf2j59Zva35Wxwn7vkasBoIuWeeglPt5a97MMi9CDlxSoi73tJ4d4sA69tV58kSh251bg-gL8SiNV54WRxmpYqwoxmeSmgqxWVH1xnNuR9gyaDVnlwVOC4si-kU8DcYF4K2VAL43wUA8QXbjH383FdEjRGUnR8EU10&t=3d6efc1f:5)

    at XMLHttpRequest._onReadyStateChange (ScriptResource.axd?d=BBrYaIMlBhMRj655qKOQMOVbx-YmqtFxf2j59Zva35Wxwn7vkasBoIuWeeglPt5a97MMi9CDlxSoi73tJ4d4sA69tV58kSh251bg-gL8SiNV54WRxmpYqwoxmeSmgqxWVH1xnNuR9gyaDVnlwVOC4si-kU8DcYF4K2VAL43wUA8QXbjH383FdEjRGUnR8EU10&t=3d6efc1f:5)

Solution: This seems to be wired issue. We cross verified code seems to be nothing wrong with that. Also same code has worked for in one of our Office 365 / SharePoint Online project.  After googling a lot, found one of the comment in following article https://sharepoint.stackexchange.com/questions/164219/problem-with-retrieving-sharepoint-list-with-js and we found that call to executeQueryAsync() method should be replaced as follows:

clientContext.executeQueryAsync(onQuerySucceeded,onQueryFailed);

We need to remove the “Function.createDelegate” part and just need to use success and failure method names and it started working like charm 🙂

Thanks for reading 🙂

Feel free to get in touch for any feedback / issue / comments / doubts 🙂

Prasham Sabadra

LIFE IS VERY BEAUTIFUL :) ENJOY THE WHOLE JOURNEY :) Founder of Knowledge Junction and live-beautiful-life.com, Author, Learner, Passionate Techie, avid reader. Certified Professional Workshop Facilitator / Public Speaker. Scrum Foundation Professional certificated. Motivational, Behavioral , Technical speaker. Speaks in various events including SharePoint Saturdays, Boot camps, Collages / Schools, local chapter. Can reach me for Microsoft 365, Azure, DevOps, SharePoint, Teams, Power Platform, JavaScript.

You may also like...

6 Responses

  1. viipiintyagi says:

    It’s good but any specific reason to depreciate “Function.createDelegate”?

  2. Ted says:

    Dude, you rock! Been trying to figure this out for a while now and this is a HUGE help! Thank you for posting!!

  3. SBTampa says:

    Thanks for this post!! It is exactly what I needed to solve the issue.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: