Giter VIP home page Giter VIP logo

nspgetlistitems's Introduction

nSPGetListItems

a JavaScript convenience library to get items from SharePoint lists using CSOM/JSOM

https://github.com/imthenachoman/nSPGetListItems

Table of Contents

  1. Overview
  2. Reference
    1. function onListLoadComplete
    2. function onViewLoadComplete
    3. function onListItemLoadComplete
    4. function onError
  3. Examples

Overview

When developing something for SharePoint the majority of the time I am getting items from a list or document library using JavaScript. I got tired of having to write the same code over and over again so I wrote the helper library/utility nSPGetListItems.

The idea is simple: call nSPGetListItems with your options (a list or document library name at minimum), and get back details about the list, the view, and, of course, the list items.

Additionally, nSPGetListItems lets you refresh the data asynchronously so you don't have to code for that.

Reference

The main function is called nSPGetListItems and it takes one key : value object. The available keys are:

Key Required Type Default Value Description Example
listName or listGUID yes string the name or GUID of the list
  • "Announcements"
  • "{1c7c0498-6f1c-4ec1-8ee6-dd9959f3c52d}"
viewName or viewGUID string the list's default view the name or GUID of the view you want to use to determine the fields and items to pull
  • "All Documents"
  • "{dce68293-70e5-4c47-acda-72e6236b8f65}"
webURL string the current web the web URL you want to pull from
  • "/someSite"
  • "/someSite/subSite"
onListLoadComplete function n/a the function to call when the list details are loaded see onListLoadComplete below
onViewLoadComplete function n/a the function to call when the view details are loaded see onViewLoadComplete below
onListItemLoadComplete function n/a the function to call when the list items are loaded see onListItemLoadComplete below
onError function n/a the function to call if there is an error at any stage see onError below
interval number n/a

onListLoadComplete

The first thing nSPGetListItems does is pull relevant data about the list based on the options you provided. If you provide a onListLoadComplete function it will be called with an object with the following properties:

nSPGetListItems({
    "onListLoadComplete" : function(listData)
});

listData:

  • listName
  • listGUID
  • viewName
  • viewGUID
  • listPermissions - boolean values to indicate if the current user has add, edit, delete, and view permissions on the list
  • listForms - URLs to the new, edit, and disp forms for the list
  • contentTypes - an array of all the content types available in the list with the following properties:
    • name
    • description
    • forms - URLs to the new, edit, and disp forms for the content type (may be empty strings)

onViewLoadComplete

Next nSPGetListItems will get details about the view you requested or the default view for the list. If you provide a onViewLoadComplete function it will be called with three parameters and expects an SP.CamlQuery return object.

nSPGetListItems({
    "onViewLoadComplete" : function(viewFields, viewXML, camlQueru)
    {
	   return camlQuery;
    }
});
  • viewFields - an array of objects providing details about each column/field, in order, from the view:
  • viewXML - the XML of the view
  • camlQuery - an SP.CamlQuery object if you want to do something custom

If you want to do something custom with the query then you can use the camlQuery paramater as the base and return an SP.CamlQuery object.

For example:

nSPGetListItems({
    "onViewLoadComplete" : function(viewFields, viewXML, camlQuery)
    {
    camlQuery.RecordCount = 100;
    return camlQuery;
    }
});

onListItemLoadComplete

a

onError

a

Examples

a

nspgetlistitems's People

Contributors

imthenachoman avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.