This project is read-only.
Project Description
JavaScript object and methods for accessing SharePoint lists using the WSS RPC Display method.

OWSAPI offers developers another way to access SharePoint data using assembly-free code. As an efficient alternative to SharePoint's web services, OWSAPI can return schema and data information from a single query.
reference: Windows SharePoint Services RPC Methods

Getting Started

Add jQuery and owsapi scripts to a SharePoint page that also has a List View Web Part. Add a document.ready instruction like the following:
$(function(){
	if (typeof ctx=='object'){ //make sure SharePoint has created an instance of ctx
		owsapi(); //create the ows object using the defaults
	}
});


This can all be done in a Content Editor Web Part, see the example in the downloads section. For a quick start, import/upload the OWSAPI Example.dwp file and add it to a list's AllItems.aspx page.

Next, explore the ows object using Firebug. Type ows in the JavaScript console, click the object returned.

2009-05-22_141931.png

Using Options

Options can override default settings. Common settings to override include view and command. Example:
$(function(){
	if (typeof ctx=='object'){
		owsapi({view:"",command:"&Query=Modified"});
	}
});


This example will return all Modified dates from the list even if Modified is not part of the default view. Using Query=* will bring back the entire schema. In jQuery 1.3.1 this causes errors in some getValues calls. Query=* should only be used during development.

Using Callback

Callback functions receive the same options parameters used in the owsapi call. Callback functions run on readyState complete (may not be successful). Calling a function that references the ows object at document.ready that is not a callback for owsapi will most likely fail because it will run asynchronously to the AJAX $.get() method and complete before the owssvr.dll returns the XML.

Example:
$(function(){
	if (typeof ctx=='object'){
		owsapi({view:"",command:"&Query=*"},function(o){
			var x = ows.getData(o.ctx);
			alert(x.length);
		});
	}
});

Using Filters

Filters are objects with multiples of three members. Each filter must include a field name, operator, and value. Multiple filters are chained together in the same object and are processed in the order they appear in the filter object. Example:
$(function(){
	if (typeof ctx=='object'){
		owsapi({view:"",command:"&Query=*"},function(o){
			var x = ows.getValues(o.ctx,"% Complete",["% Complete","<",1]);
			alert(x);
		});
	}
});


Example with two filters:
$(function(){
	if (typeof ctx=='object'){
		owsapi({view:"",command:"&Query=*"},function(o){
			var x = ows.getValues(o.ctx,"% Complete",["% Complete","<",1,"Status","!=","Completed"]);
			alert(x);
		});
	}
});


The field name used in the query need not match the rsname/field name in owsapi's second parameter. This allows for more dynamic ranges and filters. See the inline documentation about valid operators as both lookup values and lookup IDs can be used as filter criteria.

Get Data From Several Web Parts

With the following example, you can collect the list and view data from multiple list view web parts and create an ows object that contains all of the relevant data.
$(function(){
	var d = $("table.ms-listviewtable[id]");
	d.each(function(i,e){
		var arr = e.id.replace("}-{","}|{").split("|");
		arr.push($(e).attr("summary"));
		owsapi({ctx:arr[2],list:arr[0],view:arr[1]}, function(o){alert(o.ctx);});
	});
});


The above script will create objects like ows.Tasks or ows.Contacts. If the name has spaces or special characters, you may need to use the bracket notation {"(e.g., ows["Shared Documents"]).

Last edited May 24, 2009 at 5:41 AM by AutoSponge, version 19