My new blog present here.

Featured Post

Insights into Sitecore Search: A Definitive Introduction

A key component of digital experience management is effective information retrieval. A simplified approach is required for websites, applications, and platforms containing a lot of material so that consumers can easily get the data they require. This need is met by Sitecore, a well-known name in the field of digital experience platforms (DXPs), which provides powerful and comprehensive search functionality. We will travel into the realm of Sitecore Search in this article, learning about its capabilities, architecture , and the enormous value it offers both developers and end users. Introduction to Sitecore Search    A headless content discovery platform powered by AI , Sitecore Search enables you to build predictive and custom search experiences across various content sources. To extract and index you

SPServices:Update multiple items in SharePoint List or Document Library using SPServices jQuery library in SharePoint

Update multiple items in SharePoint List or Document Library using SPServices jQuery library in SharePoint

In SharePoint 2013 we can utilize client side code to update the list item. The client side scripting includes:

  • JSOM (JavaScript Object Model)
  • REST API using JQuery AJAX call
  • SPServices JavaScript Add-on


In this article, i will explain How to use SPUpdateMultipleListItems function of SPServices JavaScript add-on to Update or Delete Multiple/Single Items.

The details of $().SPServices. SPUpdateMultipleListItems operation are:

[pre class="brush:jscript" ] $().SPServices({ webURL: {web URL}, async: {true/false}, listName: {List Name}, CAMLQuery: {caml Query}, batchCmd: {"Delete" or "Update"}, valuepairs: {key/value pair of columns}, ID: {Id of the row, when update record}, completefunc: function (xData, Status) { console.log('List items has been updated'); } }); [/pre]

  • webURL: This allows you to change the context for the operation to a different site
  • async: you can pass true or false
  • listName: Name of the list from which data needs to be fetched
  • CAMLQuery: The CAMLQuery option allows you to specify the filter on the list. CAMLQuery here should contain valid CAML such as:

         [pre class="brush:jscript" ] var camlQuery = ''; camlQuery += ''; camlQuery += "Yes; camlQuery += ''; camlQuery += ''; [/pre]
  • batchCmd: We can set value as "Delete" or "Update".
  • valuepairs: It is an optional parameter and used to define Key/Value pair. If you specify updates then valuepairs should not be specified.


valuepairs: [["Title", "Amit Kumar"], ["Technologies", ".NET, SharePoint, AngularJS"]]

  •     ID: It’s an optional parameter and needs to be used with valuepairs  when we are using the batchCmd as "Update".


Update single item the SharePoint List using $().SPServices. SPUpdateMultipleListItems operation with valuepairs option:
[pre class="brush:jscript" ] var camlQuery = ''; camlQuery += ''; camlQuery += "Yes; camlQuery += ''; camlQuery += ''; $().SPServices({ async: false, batchCmd: "Update", listName: "AmitKumar_TestList", ID: 1, valuepairs: [["Title","Amit Kumar"]], CAMLQuery: camlQuery, completefunc: function (xData, Status) { console.log('List items has been updated'); } }); [/pre]




In the above code block, we are using "Update" batchCmd with ID attribute to update single item.

Delete mulitple item the SharePoint List using $().SPServices. SPUpdateMultipleListItems operation with valuepairs option: 

[pre class="brush:jscript" ] var camlQuery = ''; camlQuery += ''; camlQuery += "Yes; camlQuery += ''; camlQuery += ''; $().SPServices({ async: false, batchCmd: "Delete", listName: "AmitKumar_TestList", CAMLQuery: camlQuery, completefunc: function (xData, Status) { console.log('List items has been updated'); } }); [/pre]

In the above code block, we are using "Delete" batchCmd with CAMLQuery attribute to delete multiple items.

The SPUpdateMultipleListItems function works like this:

It first calls GetListItems with the provided CAMLQuery to find all off the items which meet the criteria
Then the function calls UpdateListItems and updates all of the items found with the values provided.

Reference: https://github.com/sympmarc/SPServices/wiki/SPUpdateMultipleListItems   

Comments

Unknown said…
Thanks for the post, Useful One

Also See: AngularJS Training in Chennai
Hey keep posting such good and meaningful articles.

Popular posts from this blog

Sitecore GraphQL Queries

Configuring Sitecore Next.js Headless SXA Multisite App in a Sitecore Container

Sitecore Experience Manager Cloud (XM Cloud) Building blocks