SharePoint ECMAScript (Client Object Model) Empty List Helper

Lists are a lot more useful as data storage mechanisms in SharePoint 2010 since there are important relational features finally built into them. Coupled with the client object model features you can start to do some really nifty data manipulation with some quick, easy code. As such, I have been starting to build up a bunch of bulk list operations that I’m using in a static manner for both some internal as well as client applications.

In the below helper function, I am emptying the items out of a list. It’s actually probably better to abstract the list title to the emptyListHelper parameters so you can pass in a string in a shared manner, so that’s might be a good idea.

[js]
var siteUrl = ‘/AdamBuenz/EmptyItemsTest’;

function emptyListHelper() {
var clientContext = new SP.ClientContext(siteUrl);
var list = clientContext.get_web().get_lists().getByTitle(‘TestList’);
var camlQuery = new CamlQuery();
camlQuery.set_viewXml(“Some Value To Match Value100“;
this.listItems = list.GetItems(camlQuery);
clientContext.Load(this.listItems);
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}

function onQuerySucceeded() {
var listItemEnumerator = this.listItems.getEnumerator();
while (listItemEnumerator.moveNext()) {
var item = listItemEnumerator.get_current();
item.DeleteObject();
}
}

function onQueryFailed(sender, args) {
alert(‘Request failed. ‘ + args.get_message() + ‘\n’ + args.get_stackTrace());
}

[/js]

Share

Resolving “the local SharePoint server is not available” Error

When doing development with SharePoint, it is pretty well-known that because you develop directly against the object model that the environment must have SharePoint present. However, at a client this morning I was helping to build some test and development environments and for some reason the error:

“the local SharePoint server is not available”

kept bubbling up, when clearly there was a local SharePoint instance present. This error can occur after a variety of actions, such as invoking SharePoint Explorer or in visual studio deployment steps.

The quickest way to resolve the error make sure that the account being used to run Visual Studio is a db_owner on the SharePoint config and SharePoint admin databases.

Share