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 ...

SPServices:How to create/add folder in SharePoint List or Document Library using SPServices jQuery library in SharePoint

In my previous article, How to access list of folder name from SharePoint List or Document Library using SPServices jQuery library in SharePoint, I already explained about $().SPServices.GetListItems operation to access the listing of folder.

Take an example of one requirement: In SharePoint online site, we need to create the folder in SharePoint List or Document library when user click on button.

To implement above requirement, we can not use the SharePoint Server Side code, so we need to utilize the Client Side Scripting – JSOM/Call to SharePoint REST API using JQuery/Use of SPServices JQuery Library.

Now, I am going to explain how to create/add folder in SharePoint List or Document Library using SPServices jQuery library in SharePoint. SPServices JavaScript Library ($().SPServices) provides function called UpdateListItems to update content in the SharePoint list.
The $().SPServices.UpdateListItems function details are:

[pre class="brush:jscript" ] $().SPServices({ operation: "UpdateListItems", async: {true/false}, listName: {List Name}, batchCmd: {"New" or "Update"}, updates: {caml Query}, valuepairs: {key/value pair of columns}, ID: {Id of the row, when update record}, webURL: {web URL} }); [/pre]


  • operation: name of the $().SPServices operation is "UpdateListItems "
  •  async: you can pass true or false
  •  listName: Name of the list from which data needs to be fetched
  •  batchCmd: We can set value as "New" or "Update".
  •  updates: It is an optional parameter and used to define caml Query. If you specify valuepairs then updates should not be specified.
  • valuepairs: It is an optional parameter and used to define Key/Value pair. If you specify updates then valuepairs should not be specified.
  • ID: It’s an optional parameter and needs to be used with valuepairs  when we are using the batchCmd as "Update".
  • webURL: This allows you to change the context for the operation to a different site

Note that if you decide to use the valuepairs approach, you also need to specify the ID option. The default for the batchCmd option is 'Update'. Also, the choices for Cmd are [New, Update, Delete, Moderate].

Now, Create folder inside the SharePoint Document Library or List using $().SPServices.UpdateListItems operation with CAML query:
[pre class="brush:jscript" ] var folderName= 'Amit_Kumar'; var camlQuery = '' + '' + '1' + '' + folderName + '' + '' + folderName + '' + '' + ''; $().SPServices({ operation: "UpdateListItems", async: false, listName: "documents", updates: camlQuery , completefunc: function(xData, Status) { //--You can perform any action, when create request completed } }); [/pre]

In the above code block, we are not using batchCmd/valuepairs/ID attributes of "UpdateListItems" operation, because CAML query contains information about command type and all required details.

Comments

I don’t know how should I give you thanks! I am totally stunned by your article. You saved my time. Thanks a million for sharing this article.

Popular posts from this blog

Sitecore GraphQL Queries

Sitecore Experience Manager Cloud (XM Cloud) Building blocks

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