kamagra how much to take

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.

  1. var siteUrl = '/AdamBuenz/EmptyItemsTest';
  3. function emptyListHelper() {
  4. var clientContext = new SP.ClientContext(siteUrl);
  5. var list = clientContext.get_web().get_lists().getByTitle('TestList');
  6. var camlQuery = new CamlQuery();
  7. camlQuery.set_viewXml("<View><Query><Where><Eq><FieldRef Name='Some FieldRef'/><Value Type='Text'>Some Value To Match Value</Value></Eq></Where></Query><RowLimit>100</RowLimit></View>";
  8. this.listItems = list.GetItems(camlQuery);
  9. clientContext.Load(this.listItems);
  10. clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
  11. }
  13. function onQuerySucceeded() {
  14. var listItemEnumerator = this.listItems.getEnumerator();
  15. while (listItemEnumerator.moveNext()) {
  16. var item = listItemEnumerator.get_current();
  17. item.DeleteObject();
  18. }
  19. }
  21. function onQueryFailed(sender, args) {
  22. alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
  23. }

One Comment

  1. Mark Short says:

    great post as usual!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>