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 Microsoft 365 Junction, Speaker, Author, Learner, Developer, Passionate Techie. Certified Professional Workshop Facilitator / Public Speaker. Believe in knowledge sharing. Around 20+ years of total IT experience and 17+ years of experience in SharePoint and Microsoft 365 services Please feel free me to contact for any SharePoint / Microsoft 365 queries. I am also very much interested in behavioral (life changing) sessions like motivational speeches, Success, Goal Setting, About Life, How to live Life etc. My book - Microsoft 365 Power Shell hand book for Administrators and Beginners and 100 Power Shell Interview Questions - https://www.amazon.in/Microsoft-Administrators-Beginners-Interview-Questions/dp/9394901639/ref=tmm_pap_swatch_0?_encoding=UTF8&qid=1679029081&sr=8-11

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.

Leave a Reply to SBTampaCancel reply

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

Discover more from Microsoft 365

Subscribe now to keep reading and get access to the full archive.

Continue reading