Query SharePoint list using jQuery SPServices

SharePoint list can be queried using jQuery SPServices library. We need to download the SPServices jQuery file from the codeplex and add to the SiteAssets .

Below is the code to create the list items using SPServices:

<script src="http://sp2010/sites/SPLab/SiteAssets/jquery-1.8.0.js" type="text/javascript"></script>
<script type="text/javascript" src="http://sp2010/sites/SPLab/SiteAssets/jquery.SPServices-0.7.0.js" ></script>

<script type="text/javascript">
$(document).ready(function() {
var fieldsToTRead = "<ViewFields>" +
                     "<FieldRef Name='Name' />" +
                     "<FieldRef Name='Department' />" +
                     "</ViewFields>";

  $().SPServices({
    operation: "GetListItems",
    listName: "UserInfo",
    CAMLViewFields: fieldsToTRead,
    completefunc: function (xData, Status) {
      $(xData.responseXML).SPFilterNode("z:row").each(function() {
        var liHtml = "<li>" + $(this).attr("ows_Name")+ "</li>" +
        "<li>" + $(this).attr("ows_Department")+ "</li>";
        $("#tasksUL").append(liHtml);
      });
    }
  });
});
</script>
<ul id="tasksUL"/>


Comments

Popular posts from this blog

Copilot Studio Azure OpenAI with SharePoint Data Source

Create and Deploy custom copilot to SharePoint Site (Part 2)

Copilot Announcements from Microsoft Build 2024