GetListItems not showing all columns in SharePoint

I struggled with this for a while today. I was using SPServices’ GetListItems to pull data from SharePoint. I was using an external content type, and for the life of me could not figure out why the query was only pulling in some of my columns. The others just weren’t there. So I searched the web for a while, coming up with nothing that seemed to pertain to me. So I decided to look at my data. Turns out those columns didn’t have any data! So, in short, look at your data! I was using SPXmlToJson, as well as just the standard $.each() function to try to pull those columns; but with no data, nothing was coming back.

Bottom line: look at your data first!

Part 2: Sort a javascript array of dates from SharePoint

This is more of a follow-up to my post yesterday on how to convert dates from SharePoint to javascript. Today I’ll show you how to pull a list of dates from SharePoint (as well as other fields), push them into an array, and then sort that array by date.

Problem: Pull a list of reservations from a SharePoint and order them chronologically. There are three fields, firstName, lastName, and startTime. We want to pull all three fields, and then output those fields into an unordered list. As an added trick, we have several reservation lists we need to pull from (Elementary School, Middle School, and High School). So all reservations need to be pulled, and then sorted chronologically.

Solution 1: Just modify your CAML query to OrderBy the startTime field. Well, this works fine. But when pulling from multiple lists (using SPServices), the results will essentially be “grouped” by list.

Solution 2: Push all results to a javascript array, then sort the array. The problem here is that SharePoint’s date/time field isn’t very javascript-y. So sorting won’t work.

Solution 3: Use the convertSPDate() function mentioned in yesterday’s post on converting dates from SharePoint to javascript, then follow solution 2!

Here’s the code (commented with explanations):

Convert a SharePoint date/time field to a javascript Date() object

In a recent project I was looking for a way to sort an array of dates brought back from SharePoint. This worked fine in Chrome, but then I realized it didn’t work in any other browsers! So, by writing a few console.log() lines to test with Safari & FireFox, I discovered that the date that SharePoint passes is seen to javascript as an “invalid date” to almost all browsers. So, here’s a small helper function that just converts what you get from SharePoint into a true javascript Date() object. Hope you find it helpful! I’ve also included it in my code section as a Gist, so grab just the function there if you’d like.


function convertSPDate(d) {
/*
*	A function to convert a standard SharePoint
*	date/time field (YYYY-MM-DD HH:MM:SS) to a
*	javascript Date() object
*
*	Author: Ben Tedder (www.bentedder.com)
*/
    // split apart the date and time
	var xDate = d.split(" ")[0];
	var xTime = d.split(" ")[1];

    // split apart the hour, minute, & second
	var xTimeParts = xTime.split(":");
	var xHour = xTimeParts[0];
	var xMin = xTimeParts[1];
	var xSec = xTimeParts[2];

    // split apart the year, month, & day
	var xDateParts = xDate.split("-");
	var xYear = xDateParts[0];
	var xMonth = xDateParts[1];
	var xDay = xDateParts[2];

	var dDate = new Date(xYear, xMonth, xDay, xHour, xMin, xSec);
	return dDate;
}

	// create a couple of variables
	var startTime;
	var convertedStartTime;

	// a standard SPServices call
	$().SPServices({
		operation: "GetListItems",
		webURL: myListURL,
		async:false,
		listName: myListName,
		CAMLRowLimit: 1,
		completefunc: function (xData, Status) {
			$(xData.responseXML).SPFilterNode("z:row").each(function(i){
				// set the value of startTime to standard SP date/time field
				startTime = $(this).attr("ows_startTime");
			})
		}
	});

	// set the convertedStartTime to a true javascript date
	convertedStartTime = convertSPDate(startTime);

Stream RTSP video in SharePoint without a plugin

This is actually a bit more straightfoward than you might think. Recently we were dealing with trying to stream a live camera feed to a public-facing SharePoint 2010 website. The stream was in this format:

rtsp://xxx.xxx.xxx.xx/wstream.sdp

I tried Bamboo Solutions’ Video Library solution, but it didn’t accept the .sdp file format. So instead, I put a content editor webpart on the page, and used the following Quicktime embed code (thanks to this site) and it worked like a charm!

<object width="480" height="285" classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab">
<param name="src" value="http://downloads.netro.ca/qtlogo.mov">
<param name="qtsrc" value="rtsp://xxx.xxx.xxx.xx/wstream.sdp">
<param name="autoplay" value="true">
<param name="controller" value="true">
<param name="loop" value="false">
<embed src="http://downloads.netro.ca/qtlogo.mov" qtsrc="rtsp://xxx.xxx.xxx.xx/wstream.sdp" autoplay="true" controller="true" loop="false" pluginspage="http://www.apple.com/quicktime/download/" height="285" width="480">
</object>

Strange case of “Export to Excel” not working in SharePoint

Ok, the title isn’t descriptive enough. Here is what I’ve run across. When the user permissions on the list (in my example, the user has Full Control of the list) are greater than permissions on the parent site (no permissions in my case), then the user can do anything the to the list (create, delete, edit, etc.). However, she cannot use the Export to Excel feature. It must be something to do with the User Client Integration permission level, but I can’t seem to figure it out. So fixing the issue just involved giving the user simple Read permissions on the parent site.

Anyone else come across this?

Using Google Maps API with SharePoint, jQuery, and SPServices

Ok, that title is a mouthful. But I just posted an article on Nothing But SharePoint detailing how you can use jQuery, SPServices, and the Google Maps API to make a fun SharePoint solution. Check out the video below and read jQuery + SharePoint Case Study: Google Maps and SPServices to see the full solution.

SharePoint Success!

This is meant to be a little encouragement in the midst of your day of end users telling you SharePoint is “hard to use,” “counter-intuitive,” or any other expletive adjective of their choice. With a little stylistic care and a little luck, you can have successes that take you a long way down the road of End User adoption!

A couple of weeks ago I wrote an article briefly describing a scheduling system built in SharePoint using nothing but 3 lists, a standard publishing page, and some jQuery.

The goal: to direct parents of 700 students to the online scheduling system for Parent-Teacher Conferences. All bookings had to be performed in the 10 days leading up to the 2-day conferences. A parent could book one slot with each of their child’s teachers, and each slot was 20 minutes long from 12 noon until 6pm. Keep in mind, no signup of this kind has ever been done electronically at this school. Previously everything was on slips of paper delivered in backpacks…followed up by half a day of phone calls to the secretaries.

The potential concerns:

  • no ability to “train” parents how to use the system, it must be intuitive
  • a good portion of the parent population speak English as a second language, with mostly Chinese or Korean as a first/only language, and about 2 dozen other languages next to those.
  • all bookings must be made ENTIRELY online (no call-ins, paper signups or emails…for consistency)
  • everyone must book their “own” slots (teachers nor secretaries can book time slots for parents)
  • parents must be able to change their time slots at will
  • priority must be given in the following order:
    • Teachers (to block certain slots for coffee breaks, etc)
    • Teachers who have children at the school (to book slots for their children)
    • Parents with more than one child in the school
    • Parents with only one child in the school (everyone else)

So, on to the success!

As of this writing we’ve just finished Day 8 of the rollout, and we have 612 students who have been booked using the system! By my count that’s just under 88% of children in the school. Now you’re probably about to ask “so how many phone calls and emails did you get?” I don’t have an exact number, but I’d say we’ve received about 20-25 calls/emails from people with “issues.” So with a 96% success rate (4% margin of error) on this first-time rollout, I’m happy!

A breakdown of the issues we did encounter:

  • a glitch where about 4 double-bookings occurred
  • a bug that wasn’t allowing users on IE7 to proceed with bookings (a simple browser switch did the trick until the fix was applied)
  • a glitch where about 5 or 6 parents were able to book slots that the teachers had blocked out
  • several login issues (separate from the actual scheduling system)
  • 2 cases of “my children” not appearing because of data integrity issues (extra spaces in names being pulled from the SQL server)

All that to say, don’t give up on your SharePoint end users! If a system is necessary enough and simple enough, you can bring them on board faster than you may initially have thought.