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 Data using SPServices jQuery library in SharePoint

How to access List Data using SPServices jQuery library in SharePoint

In my previous article, what is SPServices, I already explained about this JavaScript add-on.
Now, I am going to explain how to access List Data using 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 would be:
[pre class="brush:jscript" ] function getListDetails() { var objResults = null; var camlQueryOptions = ''; var camlQuery = ""; var listName = 'EmployeeDetails'; //--To get all Active items camlQuery = ""; camlQuery += ""; camlQuery += "Yes"; camlQuery += ""; camlQuery += ""; var listPromise = $().SPServices({ operation: "GetListItems", async: false, listName: listName, CAMLQuery: camlQuery, CAMLQueryOptions: camlQueryOptions }); listPromise.success(function () { if ($(listPromise.responseText).find("ErrorText").length > 0) { //--If error occured objResults = JSON.parse('{ "status": "error", "message": "servicecallError" }'); console.log($(listPromise.responseXML).find("ErrorText").text()); console.log(objResults); } else if ($(listPromise.responseXML).find("row").length > 0 || $(listPromise.responseXML).SPFilterNode("z:row").length > 0) { //--If success var objListItem; var listData = []; var tempDate = null; var newDate = null; $(listPromise.responseXML).SPFilterNode("z:row").each(function () { objListItem = new Object(); if (!commonfunctions.helpers.isNullOrEmpty($(this).attr('ows_ID'))) { objListItem.itemId = $(this).attr('ows_ID'); } else { objListItem.itemId = "0"; } if (!commonfunctions.helpers.isNullOrEmpty($(this).attr('ows_Title'))) { objListItem.empEnterpriseId = $(this).attr('ows_Title'); } else { objListItem.empEnterpriseId = ""; } if (!commonfunctions.helpers.isNullOrEmpty($(this).attr('ows_EmpName'))) { objListItem.empName = $(this).attr('ows_EmpName'); } else { objListItem.empName = ""; } if (!commonfunctions.helpers.isNullOrEmpty($(this).attr('ows_EmpEmail'))) { objListItem.empEmail = $(this).attr('ows_EmpEmail'); } else { objListItem.empEmail = ""; } if (!commonfunctions.helpers.isNullOrEmpty($(this).attr('ows_IsAccepted'))) { objListItem.isAccepted = $(this).attr('ows_IsAccepted'); } else { objListItem.isAccepted = ""; } 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); } }); listPromise.error(function () { if ($(listPromise.responseXML).find("errorstring").length > 0) { //--If error occured objResults = JSON.parse('{ "status": "error", "message": "' + $(listPromise.responseXML).find("errorstring").text() + '" }'); console.log(objResults); } }); listPromise.fail(function () { if ($(listPromise.responseXML).find("errorstring").length > 0) { //--If error occured objResults = JSON.parse('{ "status": "error", "message": "' + $(listPromise.responseXML).find("errorstring").text() + '::Status Text:' + listPromise.statusText + '" }'); console.log(objResults); } }); return objResults; } [/pre]


With the help of above function, you can get the data from the list 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