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:How to access list of folder name from SharePoint List or Document Library using SPServices jQuery library in SharePoint

In my previous article, How to access List Data using SPServices jQuery library in SharePoint, I already explained about $().SPServices.GetListItems.

Now, I am going to explain how to get listing of folders including sub-folders in a SharePoint List or Library with SPServices. SPServices JavaScript Library ($().SPServices) provides function called GetListItems to access the data from list.
The GetListItems function details are:
[pre class="brush:jscript" ] $().SPServices({ operation: "GetListItems", async: {true or false}, listName: {list name}, CAMLQuery: {caml query}, CAMLQueryOptions: {caml Query Options}, webURL: {weburl} }); [/pre]
  • operation: name of the $().SPServices operation is "GetListItems"
  • async: you can pass true or false
  • listName: Name of the list from which data needs to be fetched
  • CAMLQuery: You can mention the CAML query XML with filters. For example, if one of the column name in list is IsAction, then sample CAML query would be:
[pre class="brush:jscript" ] var camlQuery = ""; camlQuery += ""; camlQuery += "Yes"; camlQuery += ""; camlQuery += ""; [/pre]
  • CAMLQueryOptions: You can mention CAML query options like Recursive. For example, you have to fetch the data from sub-folder also then sample CAML query options would be:
[pre class="brush:jscript" ] var camlQueryOptions = ''; [/pre]
  • webURL: This allows you to change the context for the operation to a different site
Now, complete $().SPServices.GetListItems operation call  to get listing of folders including the sub-folders would be:

[pre class="brush:jscript" ] function geFolderListing() { var folderPromise = null; var objResults = null; var listName = 'EmployeeDetails'; folderPromise = $().SPServices({ operation: "GetListItems", async: false, listName: listName, }); folderPromise.success(function () { if ($(folderPromise.responseText).find("ErrorText").length > 0) { //--If error occured objResults = JSON.parse('{ "status": "error", "message": "servicecallError" }'); console.log($(folderPromise.responseXML).find("ErrorText").text()); console.log(objResults); } else if ($(folderPromise.responseXML).find("row").length > 0 || $(folderPromise.responseXML).SPFilterNode("z:row").length > 0) { //--If success var objListItem; var listData = []; $(folderPromise.responseXML).SPFilterNode("z:row").each(function () { objListItem = new Object(); objListItem.folder = $(this).attr('ows_Title'); listData.push(objListItem); objListItem = null; }); objResults = ({ status: success, message: listData }); console.log(objResults); } else { //--If error occured objResults = JSON.parse('{ "status": "error", "message": "servicecallError::Status Text:In succcess->else block." }'); console.log(objResults); } }); folderPromise.error(function () { if ($(folderPromise.responseXML).find("errorstring").length > 0) { //--If error occured objResults = JSON.parse('{ "status": "error", "message": "' + $(folderPromise.responseXML).find("errorstring").text() + '" }'); console.log(objResults); } }); folderPromise.fail(function () { if ($(folderPromise.responseXML).find("errorstring").length > 0) { //--If error occured objResults = JSON.parse('{ "status": "error", "message": "' + $(folderPromise.responseXML).find("errorstring").text() + '::Status Text:' + folderPromise.statusText + '" }'); console.log(objResults); } }); return objResults; } [/pre]
With the help of above function, you can get the listing of all folders including sub-folders from the SharePoint list or document library using SPServices JavaScript library.

More articles on SPServices:
What is SPServices
How to access List Data using SPServices jQuery library in SharePoint
How to access list of folder name from SharePoint List or Document Library using SPServices jQuery library in SharePoint
How to create/add folder in SharePoint List or Document Library using SPServices jQuery library in SharePoint
Update item in SharePoint List or Document Library using SPServices jQuery library in SharePoint

Comments

Popular posts from this blog

Sitecore GraphQL Queries

Twenty 20 Masti:

Sitecore Experience Edge GraphQL Queries