Question

I'm trying to make a JavaScript query on SharePoint 2010 via the following code.

On query success I got no problem, but if query fails I get "args is undefined".

All examples I see works same way I do, but I don't understand why I'm getting this error.

 function getEspais(url) {
   this.clientContext = new SP.ClientContext(url);
   this.collNavNode = clientContext.get_web();
   this.subWebs = this.collNavNode.get_webs();
   clientContext.load(this.subWebs);
   clientContext.executeQueryAsync(
     Function.createDelegate(this, function(){ _returnParam = successEspais(); }),
     Function.createDelegate(this, function(){ _returnParam = onQueryFailed(); })
   );
 }

 function successEspais(sender, args) {
     // Works perfectly!
 }

 function onQueryFailed(sender, args) {
    // Getting error 'args is undefined'    
    alert('Consulta fallida. ' + args.get_message() + '\n' + args.get_stackTrace());
 }
Was it helpful?

Solution

Try your code like:

clientContext.executeQueryAsync(successEspais, onQueryFailed);

function successEspais(sender, args) {
     // Works perfectly!
}

function onQueryFailed(sender, args) {
    // Getting error 'args is undefined'    
    alert('Consulta fallida. ' + args.get_message() + '\n' + args.get_stackTrace());
}
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top