GithubHelp home page GithubHelp logo

suhdev / stickyants-sp-util Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 83 KB

A set of utility functions and classes for SharePoint Online, SharePoint 2013, 2016 development to simplify working with JSOM.

TypeScript 40.18% JavaScript 59.82%
sharepoint jsom utilities termstore

stickyants-sp-util's Introduction

stickyants-sp-util

A set of utility functions and classes to support SharePoint development using JSOM. The library simplifies some of the tasks and uses ES6 promises to wrap executeQueryAsync calls such that they work nicely together.

1 Term Store (Taxonomy)

1.1 Working with the term store

import {createTermStore} from 'stickyants-sp-util'; 


var store = createTermStore(); 

//to get all terms of a term set
var terms = await store.getAllTermsByTermSetId('11365da4-d7cd-43b3-9d28-9d43b0313f2f'); 

2 Link Generation

2.1 Generate link to user picture by user email address

import {getUserPictureLink} from 'stickyants-sp-util'; 


var pictureUrl = getUserPictureLink('[email protected]');

2.2 Generate delve profile of user by email user email address

import {getUserDelveLink} from 'stickyants-sp-util'; 


var delveLink = getUserDelveLink('[email protected]');

2.3 Generate a link to specific version of the current page using UI Version

import {createVersionLink} from 'stickyants-sp-util'; 

//first major version link 
var delveLink = createVersionLink(512);

3 Using async/await to work with JSOM

import {executeOnContext} from 'stickyants-sp-util'; 


var ctx = new SP.ClientContext();
var web = ctx.get_web(); 
ctx.load(web); 
await executeOnContext(ctx); 
console.log(web.get_title()); 

4 Working with folders

4.1 Creating a nested folder structure in SharePoint list

import {createFolderInListIfNotExist} from 'stickyants-sp-util'; 

var ctx = new SP.ClientContext();
var web = ctx.get_web(); 
var pages = web.get_lists().getByTitle('Pages'); 
var folder = await createFolderInListIfNotExist(ctx,pages,'folder1/folder2/folder3');//returns folder3

4.2 Check if folder exists in List

import {folderExistsInList} from 'stickyants-sp-util'; 

var ctx = new SP.ClientContext();
var web = ctx.get_web(); 
var pages = web.get_lists().getByTitle('Pages'); 
var result = await folderExistsInList(ctx,pages,'folder3'); //returns true/false

5 Publishing Infrastructure

5.1 Creating a publishing page

import {createPublishingPage} from 'stickyants-sp-util'; 

var ctx = new SP.ClientContext();
var result = await createPublishingPage(ctx,'somfile','My Content Type Name'); 

5.2 Getting page layout that is associated with a specific content type

import {getPageLayoutItemByAssociatedContentType} from 'stickyants-sp-util'; 

var ctx = new SP.ClientContext();
var result = await getPageLayoutItemByAssociatedContentType(ctx,'My Content Type Name'); 

6 SharePoint Error Codes (JSOM)

/**
 * JSOM error codes, the possible values of error codes that JSOM 
 * can return 
 */
export enum SPErrorCode {
    /**
     * The accessed item has been deleted
     */
    ItemDoesNotExist = -2147024809,
    /**
     * Some unknown error
     */
    GenericError = -1,
    /**
     * User does not have permission to access/perform operation 
     */
    AccessDenied = -2147024891,
    /**
     * A document with the same name already exist and the user is attempting to add new file/folder
     */
    DocAlreadyExists = -2130575257,
    /**
     * A version that is more recent has been saved 
     */
    VersionConflict = -2130575339,
    /**
     * List item is in recycle bin 
     */
    ListItemDeleted = -2130575338,
    /**
     * A field value that has been provided is invalid
     */
    InvalidFieldValue = -2130575155,
    /**
     * Operation not supported
     */
    NotSupported = -2147024846,
    /**
     * 
     */
    Redirect = -2130575152,
    /**
     * 
     */
    NotSupportedRequestVersion = -2130575151,
    /**
     * A specific field validation has failed 
     */
    FieldValueFailedValidation = -2130575163,
    /**
     * Item update failed validation rules
     */
    ItemValueFailedValidation = -2130575162,
}

stickyants-sp-util's People

Contributors

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