Tuesday, October 2, 2012

Traps in SharePoint 2013 API

So, SharePoint 2013 has almost full API backward compatibility? Sure. That’s great!

I mean, Microsoft did a great job making our lives easy in upgrades.

But I did find some traps while upgrading to 2013 I want to share with your guys,

I am sure these things won’t be documented anywhere – which is why I call them “traps”…

I’ll try to collect more info and add it here as I move forward.

Note: these issues are found on a pre release version and might change before production is released.

Trap #1:

We run a query on tasks list, using the default all tasks view from that list. Thing is, we got “Object not set to an instance” error coming from our query parser.

Digging in code, I found SPListView.Query used to be an empty string in 2007/2010. In some lists in 2013 this changed to null now… So, any code using or parsing the query should now check if the view query is null before accessing it, like so:

string query = listview.Query ?? “”; //Takes listview.Query if not null, otherwise takes empty string.
… work and parse query as you would before

Trap #2:

We had some code that allows the user to select a list template and aggregate all items from that list type (in our list aggregator web part). So, I set it up to run on tasks lists, after fixing Trap #1, there was no error but still no items were returned.

Reason: I added a tasks “App” in 2013, which I assumed was the same as a tasks list. but to my surprise, tasks list type is 107, while the tasks App creates a list that uses type 151 (TasksWithTimelineAndHierarchy)

In our code, I collected all available list templates on the current site, but I had a code that prevented duplicate items from being added. I checked the SPListTemplate.Name and only added the first.

It appears, that in SharePoint 2013, both list types (107 and 151) have the same name “Tasks”! So, my code was only adding the first one, 107.

I had to modify my code to take the SPListTemplate.Type.ToString() in case of a duplicate entry, which seems to do the trick, Only added a space before every capital letter so it would be formatted nicer for the user.

 

Comment if you found more interesting upgrade traps!

No comments: