Skip Ribbon Commands
Skip to main content
Home
Fewer big words, more pretty pictures.
April 27
The SharePoint & jQuery Guide

So, you've finally succumbed to the hype and decided to use jQuery in SharePoint? Good for you. I'm sure you are fully prepared with the knowledge of the pros and cons using jQuery as well as have all the requisite knowledge.

You should NOT be writing jQuery in SharePoint if…

You don't? You mean you are going to copy and paste scripts from blogs and then ask the blogger to modify the script to work for your particular circumstance? Oh, that's nice.

Wonk.SharePoint.meme.2.jpg
Well, assuming you actually want to understand what you are doing, maybe even learn a thing or two, I've decided to link to several of my past jQuery blogs in an order which will hopefully help you learn how to successfully use SharePoint and jQuery together. I'll even do my best to keep this post updated as I write new blogs on the subject.

Good luck!

Before getting started…

Make sure you have some good background knowledge.

When you start using things like SPServices and the Client Object Model to query SharePoint list data you will need to understand SharePoint's query language CAML. I always refer to it as the ugly crossbreed of XML and SQL.

If you plan to use SPServices to access SharePoint's Web Services (which I also reference in several of the blogs below), you need to get that at http://spservices.codeplex.com.

When to Choose SPServices vs. the Client Side Object Model (CSOM)

Also, if you are wondering if you should use SPServices instead of the Client Object Model you can read the helpful post put together by Marc Anderson and myself.

Be sure to keep the jQuery.com site handy as this is by far the most up-to-date site to reference the jQuery api.

The Intro to jQuery and SharePoint blogs

Here are the blogs (in learning order) to help you deploy and get started using jQuery in SharePoint.

A Dummies Guide to SharePoint and jQuery–Getting Started

This blog assumes you know nothing. What is jQuery and how can I deploy it in SharePoint?

Undoubtedly one of the most common tasks you will perform with jQuery is getting and setting SharePoint form fields. This blog walks you through the process with the most common field types. A corresponding blog post to this one is Setting SharePoint Lookup Lists w/ jQuery (+/- 20 items) because unfortunately at some point you will fall victim to this SharePoint quirk.

Creating a SharePoint Parent/Child List Relationship–No SPD Version

So, now that you understand the basics of using jQuery in SharePoint and know how to get/set SharePoint form fields, this blog helps you apply that knowledge to perform the common task of creating an automatic parent/child list relationship. There are MANY ways of accomplishing this functionality, but I actually prefer this method. It may be a little more technical than the other solutions I've blogged about for creating a Parent/Child list relationship, but this solution has the least impact on SharePoint and should also upgrade easily.

Okay, at this point you should be ready to start interacting with SharePoint list data using SPServices. This blog post walks you through the basics with a VERY commented script. If you think you have your head wrapped around reading list data with SPServices, you might also check out the following blog posts using SPServices to accomplish some tasks normally achieved using server side code:

Using SPServices & jQuery to Clone a Parent Item and All its Children – Reads items from a SharePoint List and then creates copies of those items.

Using SPServices & jQuery to Find My Stuff from Multi-Select Person/Group Field – Determines the groups a current user belongs to in order to determine if the current user is part of a group or person assigned to a list item.

A Dummies Guide to SharePoint & jQuery – An Easy to Use Content Slider

Now that jQuery and SPServices is old hat, I walk you through the process of integrating SharePoint List Data into a third party jQuery library.

Other SharePoint tips and tricks using jQuery

So, here is a smattering of other blog posts on the subject which you may find helpful, or might give you ideas for your projects. Some of them are just academic, and some you can put into practice immediately.

Using jQuery to Print a Web Part – In this blog I use a very simple third party library to print a specific web part and not the entire page.

Using jQuery to Make a Field Read Only in SharePoint – Another tip you could use to make a SharePoint form field read only.

SharePoint List Views –Quick & Easy jQuery Filter – Using a very simple script, add a filter box to an out of the box list view that filters the rows based upon what the user enters.

Using Google Maps to Populate an Address in a SharePoint New Item Form – Before I started using the Bing Map api, I played around with the Google Maps API.

A Dummies' Guide to SharePoint and jQuery–A Real World Example – A mostly academic post on the types of things you can do with jQuery to modify a page in the _Layouts directory that you don't' have direct access to.

Essential Links for the SharePoint Client Side Developer – This is a list of a lot of the jQuery/JavaScript libraries I use along with some suggestions from others. I actually need to update this list soon.

So, What's next?

What? Is this not enough? I'd say for the price you paid, it's a bargain!!

I hope to do a few blog entries on more advanced topics like Callbacks, templates, and design patterns. Also, as we move towards SharePoint vNext I do think it might be a good idea to start to wean myself off of SPServices and start using the Client Object Model more (although nothing leads me to believe that SPServices will not work in vNext). So, look for me to start a series on the Client Object Model as well and provide any tips or tricks I learn along the way.

As always, let me know what YOU want to learn and I'll see what I can do! Thanks again for stopping by.

April 12
When to Choose SPServices vs. the Client Side Object Model (CSOM)

​This is a cross post with Marc Anderson. I changed it as needed so that it makes sense to the reader of this blog.

------------------------------

Marc Anderson (@sympmarc) and I had a Twonversation with Jeff Jones (@SPJeff) about a month ago about when it is good to use SharePoint’s Client Side Object Model (CSOM) over SPServices. You can see the important bits of that conversation in the image to the right. (Yeah, it’s taken us forever to get this post done. I blame Marc.)
 
In fact, Marc and I often are asked “When should you use SPServices vs. the CSOM?” Both technologies are script-based, and both allow you to talk to SharePoint through its Web Services. However, there are some important differences to consider when you are deciding which to use,
 
In this post, Marc and I will try to give you some pros and cons for each. Many of these statements are subjective on purpose; it’s the way the two of us view the two technologies and shows some of the considerations we take into account as we make architectural choices for our clients.
 
Why You Should Be Using SPServices (says Marc)
 
SPServices is a jQuery library which I wrote and continue to work on, so I have to admit a strong bias. However, I think there are some clear reasons that you should use it in some cases. It’s not the only answer, but it’s a great tool you can use to solve real business problems.
 
SPServices exposes a wide range of SharePoint’s Web Services in either SharePoint 2007 or 2010, letting you interact with the Webs, Users and Groups, Permissions, UserProfileService, and Workflow Web Services, and more. This interaction is consistent between SharePoint 2007 and 2010, so there’s no relearning when you upgrade. (Yes, Virginia, there are still a lot of organizations out there running some flavor of SharePoint 2007.)
 
SPServices supports anonymous access to read and write to lists, and it works cross-site and cross-domain by simply specifying the webURL in the Web Service operations where it makes sense to do so. Of course, your authentication model has to allow cross-domain access.
 
The syntax in SPServices is relatively simple and pretty consistent with the way jQuery and other mainstream scripting libraries work these days. All you have to do is pass the Web Service operation you want to call, along with the required parameters in the options. No fuss, no muss. The SOAP Web Services, upon which SPServices is built, return XML and parsing XML with jQuery is old hat for most Web developers. SPServices’ reliance on the jQuery library ensures great cross-browser consistency as well. Most of the code you write using SPServices is going to work exactly the same way regardless of the browser your users have.
 
Finally, because I continue to develop SPServices – most frequently based on user input – it’s highly likely that I’ll make a new option or function available to meet your needs. I put out new releases of SPServices regularly (there were five releases in the last year) and aim to keep the library evolving and staying current with newer versions of jQuery. Obviously, keeping bugs to a minimum is an ever-present goal. Oh, and it’s free to use on Codeplex, under the MIT License.
 
Why you should be using the Client Object Model (says Mark)
 
Yeah.. yeah.. yeah… SPServices is groovy and all and Marc did a great job with it, but if you are using SharePoint 2010 it should NOT be your first choice when it comes to client side development. Why? I’m so glad you asked!
 
Unless you need anonymous access or cross site access, SPServices is actually a detriment to your SharePoint sustainability. COM is the only way to go.
 
Like it or not COM is the future and .asmx web services are the past. You need to learn the current technologies and let the outdated stuff go away. Main stream support for SharePoint 2007 ends in October and vNext is just over the horizon. Microsoft has some pretty smart people and I would not be surprised in the least if they addressed the anonymous access issue in SharePoint 15 as well as some of the other limitations.  So, if you don’t use COM and rely on older technologies you may very well find yourself rewriting a lot of code when you could have been ahead of the game.
 
Additionally COM uses RESTful Web Services and can return your data as JSON which means better performance and less data being passed over the wire. Performance is a huge issue with JavaScript and jQuery so from this standpoint alone COM is the better choice. COM is also structured much more like .NET and has a nicer “feel” to it for the average .NET developer plus it’s more developer friendly (“ows_Title” anyone?).  Lastly, COM is NOT jQuery based. It is written in ECMAScript (JavaScript to the rest of us) so there are no additional libraries or overhead needed. How’s THAT for compatibility?
 
I think it’s pretty black and white. SPServices is a great tool that I have used quite effectively, but if you are using SharePoint 2010, want better performance, a better development experience, and a technology that will definitely exist in vNext then you have to use the Client Object Model.
 
Summing it up…
 
And because I'm (Marc) typing this, I get to say that Mark is all wrong. No, that’s absolutely NOT the case, All of Mark’s points are valid, but there isn’t a one-size-fits-all answer to everything. To help you decide which directions to take for your own organization, we’ve compiled this list of pros and cons for each option. Do you have other ideas for pros and cons? If so, please post the here in the comments or on Marc’s post on his blog.
 
SPServices
 
Pros
 - A wide range of SharePoint functionality is exposed with the SOAP Web Services, much of which is not available in CSOM
 - Allows anonymous access (assuming it is enabled for the underlying objects)
 - Works cross-site and cross-domain, assuming that the authentication model you are using allows it
 - Simpler syntax than the CSOM. Simply pass the required parameters to the Web Service operation, e.g., GetListItems
 - Built on top of jQuery, which is very good at ensuring cross-browser compatibility
 - Regularly updated and refined to be compatible with new versions of jQuery and to add new functionality based on user input
 - Works identically in SharePoint 2007 and 2010 (where the same Web Services exist – see chart)
 
Cons
 - The SOAP Web Services which SPServices wraps is “old” technology which only returns XML
 - Because the SOAP Web Services are older technology, they may not be supported as long as CSOM
 
CSOM
 
Pros
 - Provides access to the “modern” RESTFul Web Services which return JSON or XML based upon your need
 - Coding patterns mirror .NET, which may make more sense to .NET developers
 
Cons
 - No anonymous access
 - No cross-site or cross-domain capabilities
 - Complicated syntax which mirrors .NET coding patterns, which may make less sense to Web developers
 - Have to create your own success and failure methods

April 11
The Expert’s Conference 2012 – 400 level sessions for all…

The Expert's Conference (TEC) is coming up fast (April 29th – May 2nd) in San Diego, CA. TEC is unique in that it is specifically geared towards in-depth, 400 level sessions that are all deep dives. No overview sessions, no intro stuff. This is where the rubber-meets-the-road and you find out exactly HOW to do that really cool stuff you've previously only seen or heard about. Remember those two slides that were glossed over at the last conference you attended and you thought "WAIT! That's what I wanted to learn about". Well, this is the conference to help you truly wrap your head around those in-depth topics.

So, somehow I have fooled the great people at Quest into thinking I'm one of those "expert" types and I have been invited to speak at TEC on... you guessed it... SharePoint & jQuery… I've got to figure out a way to get more jQuery "experts" involved so I can speak on other topics. ;)

Anyway, you may be asking yourself what exactly a 400 level jQuery session might look like? Right? I know I was. After all, once you know the basics, the skies the limits? So, after much thought and ear bending of some of my colleagues like Mr. Marc Anderson… I've put together what I hope is an insightful and useful session. At first I considered doing a deep dive into Templating, Design Patterns, Fiddler traces, and really esoteric things that would have put me to sleep. However, I always appreciate and get more out of real world examples of what you can actually do with a technology. So, what will you learn if you attend my session? So glad you asked!!

  1. Quick review of the basics – my biggest complaint about jQuery and JavaScript is the sheer number of options you have as a developer. I'm going to spend 5 or 10 minutes discussing some pros and cons about different options for development, deployment, and debugging as well as elicit opinions from you guys (hey, why shouldn't I take the opportunity to learn too?)
  2. How to read list information from multiple SharePoint lists and how to store than information for later use. I'm not going to just be reading list data and dumping it to the screen. We'll be doing some calculations on SharePoint list data from more than one list to generate some real world reports.
  3. How to use templating effectively. Wouldn't it be nice to have one dataset and just send it to different templates to display different reports or graphs? I'll show you how to achieve this and also introduce you to the concept of design patterns but don't plan on going to deep into that.
  4. After we build some useful reports, I'm going to show you how quickly you can apply a couple of third party libraries to easily create a print view of your report and import your report into tools like Excel.
  5. As time allows I'll dig into some coolness with the Bing Maps API and we can talk about some more of the visually flashy things you can do with jQuery to ooh and ahh your users.

There you have it. My goal is for you to come out of my session understanding the true potential of jQuery beyond the glitz and buzzing animations and be equipped to use it to solve real world business problems.

So, if you are tired of just scratching the surface and really want to dive deep into your favorite SharePoint subject, this is your chance to do it. Plus, San Diego is pretty sweet if you've never been before. You can register for TEC here. If the price is an issue, ping me and I may be able to find a discount code for you. Regardless, it should be a great time and I'm looking forward to learning a lot myself. After all, someday I hope to be an expert. J

 

1 - 3Next

SharePoint Architect, Developer, Blogger, Speaker, Author, and general pain in the butt.
 
Thoughts, views, and opinions expressed in this blog are solely my own.
 
Remember, the Impossible just takes longer.
​​​​
The Experts Conference