Function

$().SPServices

Certification

Certified for SharePoint 2007 Works with Caveats with SharePoint 2010
See individual Web Services pages for certification specifics.

Notes

As of version 2013.01, all calls return a jQuery deferred object aka a promise.

As of v0.7.2, the core $().SPServices() function allows for simple caching of the XML results using jQuery promises in a similar manner to that outlined in Scot Hillier's excellent post Utilizing Promises in SharePoint 2013 Apps. See the Caching page for more details.

Supported Web Services

The table below shows the Web Services for which we have implemented at least one operation (or have operations coming in planned releases) with a link to more detailed documentation, indicators for whether the Web Service is available in WSS 3.0 and/or MOSS, and links to the MSDN documentation pages. Note that there are some general syntax instructions below the table.

  SharePoint 2007   SharePoint 2010
Web Service WSS 3.0 MOSS MSDN Documentation Foundation SP2010
Alerts Available Available Alerts Web Service Available Available
Authentication Available Available Authentication Web Service Available Available
Copy Available Available Copy Web Service Available Available
Forms Available Available Forms Web Service Available Available
Lists Available Available Lists Web Service Available Available
Meetings Available Available Meetings Web Service Available Available
People Available Available People Web Service Available Available
Permissions Available Available Permissions Web Service Available Available
SiteData Available Available SiteData Web Service Available Available
Sites Available Available Sites Web Service 2007 2010 Available Available
Users and Groups Available Available Users and Groups Web Service Available Available
Versions Available Available Versions Web Service Available Available
Views Available Available Views Web Service Available Available
WebPartPages Available Available Web Part Pages Web Service Available Available
Webs Available Available Webs Web Service Available Available
PublishedLinksService   Available PublishedLinksService Web Service   Available
Official File (Records Repository)   Available Official File Web Service   Available
Search   Available Search Web Service   Available
SpellChecker   Available SpellChecker Web Service   Available
UserProfileService   Available User Profile Web Service   Available
Workflow   Available Workflow Web Service   Available
Diagnostics     Diagnostics Web Service Available Available
SocialDataService     SocialDataService Web Service   Available
TaxonomyClientService     TaxonomyClientService Web Service   Available

General Syntax

$().SPServices({
	operation: "operationname",
	[webURL: "/sitepath",]
	[option1: value1,]
	[option2: value2,]
	[async: false,]
	completefunc: function (xData, Status) {
		...do stuff...
	}
});

operation
The name of the Web Service operation (see the SDK documentation links above). Because the Web Services operations are named uniquely, you only need to specify the operation.

webURL
For Web Service operations where it makes sense, you can pass in a webURL to change the context for the AJAX call. By default, the current site (as determined by $().SPServices.SPGetCurrentSite) is used.

options
The options vary based on which Web Service and operation you are calling. In all instances, the options will take the same names as those described in the SDK.

async
By default, all of the Web Service operations are called asynchronously with AJAX. Generally, this will be the desired approach, but to force synchronicity, add the async: false option.

cacheXML
If set to true, the result's raw XML will be cached using jQuery promises in a similar manner to that outlined in Scot Hillier's excellent post Utilizing Promises in SharePoint 2013 Apps. See more about how this works on the Caching page.

completefunc
A function to call on completion of the AJAX call to the Web Service:

completefunc: function(xData, Status) {
  ...do something...
},

Example

Example call for GetListItems. This example is taken directly from SPCascadeDropdowns:

$().SPServices({
	operation: "GetListItems",
	// Force sync so that we have the right values for the child column onchange trigger
	async: false,
	webURL: opt.relationshipWebURL,
	listName: opt.relationshipList,
	// Filter based on the currently selected parent column's value
	CAMLQuery: camlQuery,
	// Only get the parent and child columns
	CAMLViewFields: "<ViewFields><FieldRef Name='" + opt.relationshipListParentColumn + "' /><FieldRef Name='" + opt.relationshipListChildColumn + "' /></ViewFields>",
	// Override the default view rowlimit and get all appropriate rows
	CAMLRowLimit: 0,
	completefunc: function(xData, Status) {
		...
	}

Example call for GetUserInfo:

waitMessage = "<table width='100%' align='center'><tr><td align='center'><img src='/_layouts/images/gears_an.gif'/></td></tr></table>";

$("#WSOutput").html(waitMessage).SPServices({
	operation: "GetUserInfo",
	userLoginName: "SHARE1\\demouser",
	completefunc: function (xData, Status) {
		$("#WSOutput").html("").append("<b>This is the output from the GetUserInfo operation:</b>");
		$(xData.responseXML).find("User").each(function() {
			$("#WSOutput").append("<li>ID: " + $(this).attr("ID") + "</li>");
			$("#WSOutput").append("<li>Sid: " + $(this).attr("Sid") + "</li>");
			$("#WSOutput").append("<li>Name: " + $(this).attr("Name") + "</li>");
			$("#WSOutput").append("<li>LoginName: " + $(this).attr("LoginName") + "</li>");
			$("#WSOutput").append("<li>Email: " + $(this).attr("Email") + "</li>");
			$("#WSOutput").append("<li>Notes: " + $(this).attr("Notes") + "</li>");
			$("#WSOutput").append("<li>IsSiteAdmin: " + $(this).attr("IsSiteAdmin") + "</li>");
			$("#WSOutput").append("<li>IsDomainGroup: " + $(this).attr("IsDomainGroup") + "</li>");
			$("#WSOutput").append("<hr/>");
		});
	}
});

Last edited Jan 2, 2015 at 9:50 PM by sympmarc, version 92

Comments

omega666 Jun 11, 2013 at 5:57 PM 
How do you set a search scope for searching?

OrginSeed Feb 3, 2013 at 4:31 PM 
Hello. I'm new to this; but, I wanted to know is it possible to retrieve a list of sites/workspaces rather than a list from the list container? I assume it has something to do with the function that's being called from operations at the start. Any help will be much appreciated.

dbjdbj Jan 29, 2013 at 9:49 AM 
Very good from an SharePoint SME point of view. But from JavaScript SME point of view your code sometimes "hurts". I mean well, I mean no harm. Example call for GetUserInfo, might be for example :

var waitMessage = "<table width='100%' align='center'><tr><td align='center'><img src='/_layouts/images/gears_an.gif'/></td></tr></table>",
$WSO = $("#WSOutput");

$WSO.html(waitMessage).SPServices({
operation: "GetUserInfo",
userLoginName: "SHARE1\\demouser",
completefunc: function (xData, Status) {
$WSO.html("<p>This is the output from the GetUserInfo operation:</p>");
$(xData.responseXML).find("User").each(function () {
var $this = $(this);
$WSO.append(
"<li>ID: {0}</li><li>Sid: {1}</li><li>Name: {2}</li><li>LoginName: {3}</li><li>Email: {4}</li><li>Notes: {5}</li><li>IsSiteAdmin: {6}</li><li>IsDomainGroup: {7}</li>".format(
$this.attr("ID"),
$this.attr("Sid"),
$this.attr("Name"),
$this.attr("LoginName"),
$this.attr("Email"),
$this.attr("Notes"),
$this.attr("IsSiteAdmin"),
$this.attr("IsDomainGroup")
)
);
});
}
});

I hope you don't mind this ....

hornerba Dec 12, 2012 at 3:34 PM 
From what I can tell, the spellchecker web service is not available in 2010 Foundation because it's tied to the Publishing infrastructure feature. Also, SPXmlToJSON description in main documentation page says Xsl instead of Xml. Feel free to delete this comment if so desired :). Absolutely love the work you have done and has helped get me leraning jQuery and more.