|
An alternative to web service queries, using the web method (RPC)
An alternative to DOM reading, using this API has significant advantages:
PurposeSo what kinds of things can we do with this tool? Feed a Charting APISeveral charting and graphing APIs are ready to take your data and make it pretty. This project hopes to make that both fast and easy. //TODO create full example with popular graph API Perform Actions on Calculated ColumnsI hear a frequent request to do something with calculated columns. Filtering, grouping, adding, averaging, etc. are all missing from the SharePoint interface. Compare ListsThis often requires a customized DVWP and a merged data source to get started. However, by parsing the owssvr.dll results into the ows object, we can quickly and easily compare arrays of values in the two lists. //TODO research a join/merge function using two or more results Getting Started
$(function(){
if (typeof ctx=='object'){ //make sure this web page queried a list already
owsapi();
}
});
That code can be included after the owsapi closure. The example will use the defaults and build an ows object and all of its methods based on ctx1 (the first List View Web Part loaded on the page). NOTE: By changing the defaults to "ctx", your default will construct the ows object around the last web part added to the page. This is in the order it was added, not loaded (see the Contents page to see the order). The base ows object will then include a ctx1 subclass. ctx1 will have two subclasses, schema and data. Schema represents the schema portion of the owssvr.dll result while data represents the rows. Using OptionsNow you can access the ows object, see the examples in the comments of each method. We can make a more complex call to owssvr.dll by passing options. An option combination I use often, in the example below, allows me to pull all schema data and all attributes for all rows (bypassing the default view): $(function(){
if (typeof ctx=='object'){
owsapi({view:"",command:"&Query=*"});
}
});
Using CallbackIf I want something to happen after the data loads, I can add a callback function. $(function(){
if (typeof ctx=='object'){
owsapi({view:"",command:"&Query=*"},function(o){
var x = ows.getData(o.ctx);
alert(x.length);
});
}
});
That will alert the number of rows returned by the query. Notice we give the callback function (o) as a parameter. This is because the owsapi will return the options back with the callback. That way, we don't have to hard-code the ctx name. We can also make another call to owsapi for ctx2 (assuming we have another List View on the page) and ows.ctx2 will be created (we don't create another ows object). If I know the List's GUID, I can create a custom ctx name and store the results in my ows object. Using FiltersSome of the methods allow filters. Filters are really nice for quickly isolating data. Here's an example: $(function(){
if (typeof ctx=='object'){
owsapi({view:"",command:"&Query=*"},function(o){
var x = ows.getValues(o.ctx,"% Complete",["% Complete","<",1]);
alert(x);
});
}
});
On a Tasks list, this will get all defined values for % Complete then filter for the rows where % Complete is < 1. You can stack filters to create ranges. For instance, ["% Complete","<",1,"Status","!=","Completed"] would also exclude Completed Tasks from being returned, even if the % Complete is less than 1. SourceSource code is now available on owsapi.codeplex.com SharePoint can have Wildcard searching... ยป Andy Burns' SharePoint Blog Labels |
OWSAPI

This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License. Hosted generously by CustomWare








