OWSAPI


Table of Contents

An alternative to web service queries, using the web method (RPC) Display method has some advantages:

  • Possible to pull a list's folders and items in the same call (e.g., Discussion Groups) - hint: use the "&ID=1" parameter
  • Possible to pull data and schema in the same call (two methods needed using pool covers and halloween contacts web services)
  • May have speed/security advantages over web services. //TODO check against large and small data sets.

An alternative to DOM reading, using this API has significant advantages:

  • DOM reading is limited to the DOM content, meaning the view used and loaded groups
  • DOM reading fails to find ID values for lookups displayed by Title
  • Custom filters, especially for calculated columns, do not exist

Purpose

So what kinds of things can we do with this tool?

Feed a Charting API

Several 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 Columns

I hear a frequent request to do something with calculated columns.  Filtering, grouping, adding, averaging, etc. are all missing from the SharePoint interface.

Compare Lists

This 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

  1. Pick an easy page to start with, any list or library default view page will work (e.g., /Lists/Tasks/AllItems.aspx).
  2. Add jQuery to your page (tested with 1.3.1).
  3. Add the owsapi script to your page (see below article).
  4. Invoke the construction of the ows object with some document.ready jquery:
$(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 Options

Now 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 Callback

If 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 Filters

Some 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.

Source

Source code is now available on owsapi.codeplex.com

SharePoint can have Wildcard searching... ยป Andy Burns' SharePoint Blog

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.



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