SharePoint, Javascript Client Object Model and Correlation Ids Reply

Mike BerrymanSharePoint has what’s known as the Client Object Model, which allows for code not located on the SharePoint server to access an object model of the SharePoint site.  One of the ways you can use this Client Object Model is by using Javascript.

I won’t go into a big tutorial about accessing the object model through Javascript (you can find these everywhere on the web), but the general idea is that it’s very asynchronous in that you set up the objects you want loaded, then call a load function with a success and fail callback.  Obviously you’d always like your code to succeed, but in the event of a failure many of the examples I’ve found out there, including on MSDN, give a snippet of code that looks something like this:
function onQueryFailed(sender, args) {
    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}

This will pop up an alert box showing the error message and strack trace.  Usually helpful, but not always.  In fact, recently I ran into an issue where the error message was completely wrong and I was getting nothing helpful from the stack trace.  It took some digging, but I was able to find that even with the Javascript Client Object Model, errors are still logged to the SharePoint Logs and I just needed to find the correlation Id.  It turns out you can get the correlation Id in the ‘args’ object, albeit probably not exactly as Microsoft intended:

args.$2F_2

There’s probably a better way to access it, but you know – when you find something that works, no need to keep digging.  This is the correlation Id to find the exact error in the SharePoint logs, and the SharePoint logs are so much more helpful than the single error message you get from the ‘args’ object.

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s