Using Git with SPServices on Codeplex

gitlogo@2xThis git thing gets a lot of press these days and I figure it’s time to learn it. I selected git as the code repo on the SPServices Codeplex site quite a while ago but never used it. Now I’m trying to figure out what would be useful.

SPServices has been a single file, as most of you know. However, each release has been made up of two js files (one minified, one not) and a license.txt, all in a ZIP file.

SPServices 0.7.2 ReleaseI’d like to be able to use git to:

  • Accept code from others and easily (relatively) merge it
  • Track changes better than I have been just on my hard drive and in my WSS 3.0 development environment
  • Provide offline documentation – This is a tricky one because I’ve used the Documentation wiki on Codeplex as my repository and I’m not sure how to pull the content out.
  • What else?

I welcome any thoughts you may have. I’m especially interested in how you think I can best accomplish the bullets about with a minimum of muss and fuss for everyone.

Paul Tavares (@paul_tavares) has already started a thread on the SPServices Discussions to get the ball rolling. Please jump in with your ideas or comment here.

Using _spPageContextInfo to Determine the Current SharePoint Context in Script

Sahil Malik had an extremely useful little post about a month back that I emailed to myself and then promptly forgot. Today, Mikael Svenson pointed back to Sahil’s in a post of his own that is also very useful. I’m going to steal a little from both posts for this one. I hope Sahil and Mikael don’t mind. I’ll ask for forgiveness later.

Mikael’s trick shows you An easy way to accomplish Home navigation links regardless of the path of your site collection just by looking at a JavaScript variable that SharePoint provides us. Knowing the current context is something I struggled with when I first was working on SPServices, and I came up with some monkey business with the WebUrlFromPageUrl operation in the Webs Web Service and some other URL hackery to figure it out. Since then, I’ve layered in checks for some of the variables that SharePoint 2010 provides to avoid Web Service calls, where possible. In the upcoming 2013.01 release, I’ll add in a few more, and even some that take advantage of some of the additional variables in SharePoint 2013. Of course, there will be fallbacks for anything that isn’t available, so the library continues to be version-resistant.

Mikael linked back to Sahil’s post _spPageContextInfo is your new best friend. In Sahil’s post, he lists the values which are available in SharePoint 2010 and 2013 in every page. Here’s the table that Sahil provides, but I’ve sorted the data alphabetically and changed the example URL to make some of the values more clear. It’s worth noting that there isn’t an SP2007 column in Sahil’s table. That’s because the _spPageContextInfo variable wasn’t introduced until SharePoint 2010. For SharePoint 2007, it’s still monkey business and URL hackery. After all, no one uses script with SharePoint 2007, right?

Assuming we are on the page https://sharepoint.com/sites/demos/SitePages/Home.aspx

[important]2013-03-27 – Added L_Menu_BaseUrl for SharePoint 2007 based on Christophe’s helpful comment below.[/important]

Name SP2007 SP2010 SP2013 Example Value
alertsEnabled X X false
allowSilverlightPrompt X X true
clientServerTimeDelta X 17856
crossDomainPhotosEnabled X true
currentCultureName X en-US
currentLanguage X X 1033
currentUICultureName X en-US
L_Menu_BaseUrl X  X X /Sites/Demos
layoutsUrl X _layouts/15
pageItemId X X 1
pageListId X X GUID
pagePersonalizationScope X 1
serverRequestPath X /Sites/Demos/SitePages/Home.aspx
siteAbsoluteUrl X http://sharepoint.com
siteClientTag X 21$$15.0.4454.1026
siteServerRelativeUrl X X /sites/Demos
systemUserKey X 1:0).w|<sid>
tenantAppVersion X 0
userId X X 30
webAbsoluteUrl X http://sharepoint.com/sites/demos
webLanguage X X 1033
webLogoUrl X _layouts/15/images/siteicon.png
webPermMasks X Object with properties High & Low
webServerRelativeUrl X X /Sites/Demos
webTemplate X 1
webTitle X Demos
webUIVersion X X 4 (2010) or 15 (2013)

SPServices and Migration to SharePoint 2013

I get many great questions in the SPServices Discussions (that’s the best place to ask questions about SPServices, IMHO, not the MSDN forums, or StackExchange, or on the Documentation pages on the SPServices site, where I rarely see them). Some of them deserve to get wider exposure by becoming a blog post, and here is one of those.

The question came in today from jshoaf and was titled Migration to SharePoint 2013:

I’m new to SPServices and I’m using it to develop on SharePoint 2010.  I’m using SPServices 0.7.2.  My organization will be upgrading to SharePoint 2013 sometime in the future.  What will I need to do (if anything) when the new SharePoint server is installed to keep using the SPServices library?  Primarily I’m using GetListItems and Query operations.

and here is my answer:

Unfortunately, the answer will have to be the dreaded “it depends”.

The SOAP Web Services are still present in SharePoint 2013, though Microsoft has decided to deprecate them. What that will mean in reality is anyone’s guess. There are lots of deprecated pieces of functionality (think sandbox) that would very difficult to remove.

The bigger question is around what you do with the results and such. The DOM in SharePoint 2013 has changed, just as it did from 2007 to 2010. If your code is nice and modular and you are using clean selectors, I would guess that you will have to re-test, perhaps adjust the code, and most likely adjust the CSS.

Keep in mind that many of the adjustments may be outside SPServices itself and just in your own jQuery / JavaScript and CSS.

The upshot of this is that there simply can’t be a simple answer. The core of SPServices will work in 2013. My testing hasn’t been extensive enough to test every single operation, but the SOAP Web Services are there in 2013 and they work the same.

As for the value-added functions, it looks like the list forms in 2013 are essentially the same as in 2010 and even 2007. It’s mind-boggling, isn’t it? One would think – at least I do – that there were so many opportunities for improvement.  I was extremely surprised when this was the case going from 2007 to 2010, and I’m incredulous that the forms are the same going from 2010 to 2013. But so it is.

The good news about having those frumpy forms stay the same is that the value-added functions that enhance them will generally work. Again, my testing hasn’t been extensive, but the functions everyone know and love – SPCascadeDropdowns being the primary one – seem to work fine. Of course, the whole iitem creation and editing expereience has been widened so that there are more possible ways to accomplish them.

Another question I often get is “Have you rewritten SPServices for 2013?” The answer for that is “no”, as there isn’t really any need, based on the details above. However, if you decide to use SPServices with SharePoint 2013 and you run into issues, I *definitely* want to hear about them – post to the SPServices Discussions. I think SPServices has a good few years left in it, and I don’t want there to be bugs with 2013 or 2007 or 2010 if I’m able to fix them.

I’m in the midst of working on a new release of SPServices that will return jQuery .Deferred() objects (aka promises) from SPServices calls. (See SPServices 2013.01ALPHA4 Returns a Deferred Object (Promise)) One of the reasons I’m doing this is that it will bring SPServices forward to reflect better coding practices if or when you may decide to move to REST-based calls to SharePoint instead of using SPServices to make SOAP calls. In other words, even if you decide to stick with SPServices, you’ll be using an approach that will make it easier to move forward with SharePoint as it evolves.

Remember that SPServices is open source. I rely on you, the community that uses it, to let me know what works and what doesn’t. There is just not enough time in a day for me to test everything. If I hear about problems, I try to get fixes out as soon as I can, but this is free software, folks. The best situation is one where someone runs into a problem, they devise a fix, and I get the fix to incorporate into future versions. That was my understanding about open source when I got started with SPServices in 2009, but in reality, it just isn’t true most of the time. Wouldn’t it be nice if it were, though?

If you have thoughts or concerns about all this, by all means let me know, preferably in the SPServices Discussions. (Have I mentioned that is the best place to get help with SPServices) Comments here are always welcome as well.

[important]This is what I’m talkin’ about! This afternoon, I got a request for functionality along with the proposed fix. Take a look at the Add support to allow SPUpdateMultipleListItems to use folders item in the Issue Tracker. I’m adding it into the new alpha for the 2013.01 release right away. This is how you can get what you’d like to see in SPServices, for sure.[/important]

MicroWork Is Just Work By a Smaller Name – Or Is It MicroHell?

David Broussard put up an interesting post on his blog the other day called MicroWork Is Just Work By Smaller Name. In the post, David says:

This is the promise of Social Business, or as I like to call it MicroWorking. When I am standing in line at the grocery store, I am often on my Smart Phone reading emails, or on Facebook, or Texting with someone…in short I am doing something in what was previously unusable time. This is the real potential of MicroWork or Social Business…turning unproductive time into productive time…especially when we are not at our desks.

  • Sitting in a conference room waiting for a meeting to start
  • Walking from one part of the building to another
  • Waiting in the lunch line
  • Walking from the car to the office
  • Getting a cup of coffee at the Starbucks

These are times that are often unproductive that can be made productive via MicroWork. What can we do in those time frames?

  • Approve invoices
  • Enter a timesheets
  • Review a document
  • Answer a question
  • Delegate a task to another person

You get the idea…the idea here is to figure out a bit of work that can be performed and turn it into a MicroWork task. In this manner we accomplish two very important things. First we make our workers more productive and second giving them work in a format that is easy to use and fits in with their lives.

I would recommend reading the entire post, as it’s quite interesting; this is just the tail end of it.

After reading the post, I was moved to add my $.02.

MicroWork is absolutely the current state of things, at least among my social circles (both words in their traditional meanings). I think it’s yet to be seen if or when there will be a backlash to this filling in all of the nooks and crannies of our time.

I know that my days now often feel too full. There’s precious little time I can set aside for self-reflection or family time where I don’t have my iPhone in my pocket. It’s become a bit of a crack high to pull it out of my pocket to see what’s going on with Facebook, Twitter, Yammer, email, etc. (in no particular order).

This is a microhell of my own doing of course.I could simply choose to shut it all off, but that gets harder all the time, as our work and “social” lives intertwine. One could posit that we are giving up too much of ourselves for the perceived benefit of others – a constant striving to belong in too many places.

The other downside I see is that work and non-work now coexist in microbursts. We are devoting increasingly smaller time slices with our attention to any particular “social” activity. If things like approving an invoice are in the “social” mix, are we paying enough attention to the details to make an informed decision? Or are those important (they are important if we need to do them, correct?) decisions becoming relegated to the importance level of clicking a “Like” button?

This new world order is undoubtedly here to stay in some form. Time will show us how it evolves from where it is, regardless what the tool makers would like to see us do.

In his response to my comment (also very worth reading), David recommended the book Hamlet’s BlackBerry: A Practical Philosophy for Building a Good Life in the Digital Age. It’s already on my Kindle, ready to go.

 

 

SPServices Stories #12 – SharePoint and jQuery SPServices in Education: A Case Study

Introduction

Ben Tedder (@bentedder) has long been a fan of SPServices and his writing about it is great, to boot. I liked this post back when Ben first put it up on his blog because it really does tell a story, and SPServices plays a significant role in it.

Ben has built quite a few real-world solutions using SPServices that transcend what SharePoint can do. By using SharePoint as the back end data repository, Ben has managed to create solutions that provide a great user experience and are far more efficient than SharePoint can be when building through the UI. He does this without deploying any server-side code, just as I always aspire to do. Great solutions with minimal footprints.

Thanks to Ben for letting me republish this post from his blog.

SharePoint and jQuery SPServices in Education: A Case Study

24 Sep 2012

bentedder-profile

This is a morphed, updated, renewed version of the SharePoint Scheduling Assistant. I’m not releasing this version quite yet, but this is a brief case study on how it’s working at a specific school.

Business Needs

The International School of Beijing needed a way for Elementary School parents to book time slots with teachers during bi-annual parent-teacher conferences.

The requirements:

  • Easy to use (training is impossible).
  • Integrate into the current intranet portal.
  • Sync with the database to omit any kind of manual setup for secretaries.
  • Deny parents the ability to book more than one slot with the same teacher.
  • Allow parents to book the same slot for two different teachers (in case mother and father come in and meet with 1 teacher each to save time)
  • If two or more parents are online at the same time, correctly queue the submissions so a double booking does not occur.
  • Allow teachers to pre-block out slots where parents cannot book times.
  • Allow teachers the ability to see their entire schedule, including which student is coming in during which time slot.

Solution (SharePoint, jQuery, and SPServices)

A SharePoint solution was built with jQuery to meet the requirements of the Elementary School. Let’s break down how the solution was created:

Part 1 – SharePoint

Within SharePoint three lists were created:

  • Bookings (Each reservation had its own row in this list that stored the details of who booked it, for which teacher, etc.)
  • Time Slots (A pre-determined list of time slots…in this case a list item was created for each 20 minute time slot from 12-6pm on Thursday and Friday Oct 18 and 19).
  • People (An external content type that pulled records from the database for each student, each of their parents, and each of their teacher names)

One of the trickier parts of this solution was grabbing the external content from the database in a usable way. Once it was in, we were able to work with the data. However, this list has 10,000+ items, so dealing with larger data like this was quite challenging. Enter jQuery.

Part 2 – jQuery and SPServices

The bulk of this solution was created with the jQuery and jQuery SPServices Libraries. Using jQuery, we stepped through the process like this:

  1. Get the details of the logged in user (parent) using SPServices
  2. Hit the SharePoint external data list once, filter it by Parent (matching to the Parent login ID), and store it in a javascript object for later use. This was the biggest strain on the system. We minimized the data call to only one time, but even still, pulling a list of 10,000 records even once isn’t super quick.
  3. Get all the children of the logged in parent, push them to a drop-down menu
  4. Get all the teachers of the selected child from #3, push them to another drop-down menu
  5. Get all time slots from the Time Slots list, push to a third drop-down menu
  6. Retroactively disable all time slot options that have already been booked (by searching through the Bookings list for records that match the time slot and the selected teacher)

Once the data was present, the parent could interact with it in two ways, book, and delete.

To book a time slot, the selected child, selected teacher, and selected time slot (along with a comments area) was submitted and saved to the list. To delete a time slot, a delete button is appended to each reservation in the on-screen schedule with the ID of the reservation as the ID of the link element.

The data from the Bookings list is checked once during the time slot selection process, and again during the form submit process to make sure no double bookings have occurred.

Benefits

This solution enables, for the first time at this school, parents to go online and manage their entire Parent-Teacher Conference schedule. Also, as an added bonus, if a mother and father both login, they can see the complete schedule for their child, even if only one of the parents made the bookings.

Once a parent books a time slot, they receive an email containing the details of their reservation.

An additional feature of this solution was that it was duplicated and tweaked for teachers to use a similar interface to pre-block out time slots where they did not want parents to come (ie, lunch, coffee break, going home). In that scenario the “one-block” restriction was removed for teachers, allowing them to customize when parents would be given the option to come in.