Retrieving SharePoint 2013 List data

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
so now we're going to talk about retrieving SharePoint lists data jQuery is great for work with share points the Dhamma is rendered by SharePoint because there's a heck a lot you can do just with that manipulating things for going on in pages enhancing the behaviors you know you can add functionality just by dropping some script into a page and not really talking to the SharePoint Server at all however lots of the time to to make your functionality work you really need to you know sort of ask your point for some data and do something with it or write some stuff back so that's what we're going to take a look at in this section there are three main methods to to get data from from SharePoint 2013 the method that I've been using back since SharePoint 2007 with SP services are the the soap or rest I'm sorry so or a SMX Web Services they're deprecated in SharePoint 2013 but they're very much still there and they actually cover a larger why a larger range of functionality and provide a wider range of services and operations then either the rest or JavaScript object model JSON capabilities that are in SharePoint 2013 so I don't I don't see this as dead technology it's definitely older but it's it's still very much there and it still works very well as I show you examples you may see you may see that it's syntax for using the soap web services is a little bit tighter I'm not going to go into all of the things that it can do or that you can do with it but you know like I said the the range of things that you can accomplish is quite a bit wider what you'd want to do is show you three different the three different access methods and sort of what the code looks like in these next couple of slides so this is an example of calling the soap web services with SP services I've just released a new version recently and we're SP services now returns deferred objects in jQuery just like you would want to use with rest or source isang in the sort of the more modern ways to talk to SharePoint so if you if you if you're coming from SharePoint 2007 or 2010 and you're used to using SP services by using these deferred objects you're actually starting to move your your thinking and your development techniques more toward the more modern stuff that you would do with 0.20 13 especially if you're interacting with it in in the cloud with office 365 or any of the other vendors where you can't deploy code to the server so in this case what we're doing is we're calling get list items to get data from Alice called cities we're storing the the result of that call in a variable called this promise and when this promise is done a deferred object or a promise is a jQuery capability and the way I think about it is you make a request and that the jQuery sort of hand you back a container it's like a Sega sealed package and jQuery says you know don't open this yet because there's nothing in this interesting yet but when there is I'll let you know then jQuery says ok it's done and you can open the box so it's a little like that suspense leading up to your birthday party when you're when you're not years old at least over my son which my son is so that's what a promise is or a deferred object it's it's the container which will be populated at some later point the may be may be populated when you get it but more likely it's going to be populated later so we make this call to the to the soap web services and you'll see this we'll see this is consistent across slippery methods you make this call to the soap web service hit those items asking for the content in cities pull it's called cities you get a promise back or a deferred object when that's done when it's been filled up we iterate through it looking for all of the the the items in the returned XML the soap web services return XML not JSON you can't request JSON so that's the reason why it's a little bit of an older Krupke Krup to your method and in this case we're just alerting the attribute the attribute on each row that or each item the vehicle the title so we would just see all of the titles popping up and an alert very very basic on purpose so that you can sort of see what the structure of this looks like so that's that's a very simple SP services call to get less items next up is a rest call this this is I think I think if you were to start with interacting with SharePoint 2013 and trying to get data out of SharePoint I would start with rest there I will talk about the the client-side object model of Java Script object model next but I think the sort of the way that the web is going is toward rest I think that while the rest implementation the SharePoint that Microsoft has done with with with SharePoint 2013 is not complete more visited here fully to the standard big surprise it's still the best way to go because you're going to have a more standard way to retrieve data you're going to have more people who can do development using jQuery using this access enough in and I think it's probably the way things are going to go as opposed to the client-side object model so in this case we're using the JavaScript Ajax function which is what we're using in I'm sorry jQuery AJAX function just like we do with SP services we pass a URL to the API we have any API URL that we can pass it perhaps a request - we're talking to the web we're going to get lists we're going to get the list by title in this case we're getting cities so very similar to what we get in the other the other SP services example and then we're going to ask for the items it's a get we have to pass this this header this except header so that we can get JSON back otherwise we get XML just like the soap web services and it has to be this particular string so what we're getting what we're doing is we're making an Eau de de request so again if you've sort of done a development fee on SharePoint Oh data is one of the big standards out there that everyone is using now with rest also again this is becoming a much more standard way just on the web in general to retrieve data and then when when that call is successful we recall a function that basically parses that data out and we take the results that work better pass back then the namespacing is of course different Microsoft never uses the same namespace twice and two different versions of things so it passes back a data object you know we've named it that here and then it's got a D namespace it's got a results set and a result for each of the items and again we're iterating through this with the final for loop in JavaScript and then we're alerting the title so very similar than the two the two links that are at the bottom are two of the best links that I found to try to explain how to make rest calls though I've got to say you know in trying to get up to speed with this the documentation that's out there is I think rather obtuse it's difficult to follow and most of the examples that are out there are there they're a little too theoretical so you know I think there's a lot of room for or more book writing or more blog posting or more whatever to give good examples of these sorts of breast calls again as I've said I think this is where things are going and I think it's where you should focus your time if you're starting with SharePoint and jQuery the third the third method is the Java side Java javascript object model there's the C saman that in the and the json they effectively look and smell the same way you'll see there's a lot more code on the page it's a little bit more to me this is this is a great method to start if you happen to be a server-side programmer more traditional sharepoint developer and you want to get into some client-side development and you just find that that javascript and jquery are a bit too confusing this feels a lot more like writing C sharp to me then then it does feel like writing writing script even though it is script so there's a there's an S pjs file that comes with SharePoint 2013 in fact you get some some of the same capabilities in SharePoint 2010 and it's again it's just a different library of functions that let you get at things from script from the client-side it's a little hard to tell but in this case you're actually building up a request and then you know sort of executing it once you once you've got all the contexts and stuff there actually are a number of different requests made to the server at this model though you know the first one is we we make a call to get the client context and we make a call to get the web to get the list and then you get the list by the title and then there's a final sort of execute the query to make the request to get all of the items so it's a little bit more chattery than then the rest call which you can sort of compact all of the of the logic in your rest call I'm not doing anything complicated here but you can do and I'll show you some examples but you can do filtering you can do sorting things like that all on one particular s call as well those expanding projections in many cases with one single call but the see some you tend to see a little bit more chatter on the line but again it's more of a I think it's more of a development pattern that's going to make sense to people who have done a lot more of the sort site coding stuff and are used to the server side effect
Info
Channel: VisualSP
Views: 40,443
Rating: 4.7959185 out of 5
Keywords: SharePoint, SharePoint 2013, JavaScript, JQuery
Id: 0IabpcX3xgY
Channel Id: undefined
Length: 10min 53sec (653 seconds)
Published: Thu Feb 27 2014
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.