Code Monkey home page Code Monkey logo

angular-spservicesrest-sharepoint's Introduction

Angular---SPServicesREST-

Angular module that simplifies the use of Sharepoint 2013 REST Service Calls

#Usage

Include the SPServicesREST.js file above your app file in script tag

Include SPServiceREST as a dependancy in your app module

##Example:

var myapp=angular.module("myApp",["SPServicesREST"])

Then reference the service in your controller

Currently 3 services are available

  • SPRESTItemServices
  • SPRESTListServices
  • SPRESTUserServices
myapp.controller('myController',[
                    '$scope',
                    'SPRESTItemServices',
                    'SPRESTListServices',
                    'SPRESTUserServices',
                    function($scope,$SPRESTItemServices,$SPRESTListServices,$SPRESTUserServices){}])

##Working Examples

##SPRESTItemServices --

Each Service Above has a set of functions

SPRESTItemServices.getItems()

myapp.controller('myController',[
                    '$scope',
                    'SPRESTItemServices',
                    function($scope,$SPRESTItemServices){
                      $scope.retrieveListItems_oData=SPRESTItemServices.getItems({
                                                  siteURL:'http://mysharepoint.com/sites/mysite', //required string
                                                  listName:'myList', //required list name string
                                                  filters:{
                                                      orderby:'Title Asc',
                                                      select:['Title','Id'],
                                                      top:3
                                                  }
                                                }).then(function(response){console.log(response)})
                    
                    }])

The request above calls the Sharepoint REST API creating this URL string -- http://mysharepoint.com/sites/mysite/_api/web/lists/GetByTitle(‘myList’)/Items?$orderby=Title Asc&$select=Title,Id&$top=3

A CAML Filter approach is also available please see below

myapp.controller('myController',[
                    '$scope',
                    'SPRESTItemServices',
                    function($scope,$SPRESTItemServices){
                      $scope.retrieveListItems_caml=SPRESTItemServices.getItems({
                                                  siteURL:'http://mysharepoint.com/sites/mysite', //required string
                                                  listName:'myList', //required list name string
                                                  caml:"<View><Query><OrderBy><FieldRef Name='Title' Ascending='TRUE'/></OrderBy><Rowlimit>3</Rowlimit></Query><ViewFields><FieldRef Name='Id'/><FieldRef Name='Title'/></ViewFields></View>"
                                                }).then(function(response){console.log(response)})
                    
                    }])

This will return the same results as the original example but it does not use OData. The Caml operater can be useful when working with null values date fields. The service does not append the CAML to the url query string but instead passes the request in the header....

No need to worry about URL Query string length here!

SPRESTItemServices.getContextInfo()

This function is used to grab the current context info of the site. In sharepoint 2013 add-ins(apps). The developer will not always have the ability to grab the requestDigest or the formDigestValue from a .NET control. Especially in an App Part. This method will allow the developer to grab the value from the site context. Returns the site Context Object

myapp.controller('myController',[
                    '$scope',
                    'SPRESTItemServices',
                    function($scope,$SPRESTItemServices){
                      $scope.retrieveSiteContext=SPRESTItemServices.getContextInfo('http://mysites.com/sites/mysitecollection')
                                                        .then(function(response){
                                                          console.log(response)
                                                          console.log(response.d.GetContextWebInformation.FormDigestValue)
                                                          })
                    
                    }])

The function calls the REST API http://mysites.com/sites/mysitecollection/_api/contextinfo

SPRESTItemServices.createItem()

To Be Written

##SPRESTListServices --

SPRESTListServices.getList()

Example:

myapp.controller('myController',[
                    '$scope',
                    'SPRESTListServices',
                    function($scope,$SPRESTListServices){
                      $scope.retrieveListObj=SPRESTItemServices.getList({
                                                        siteUrl:'http://mySite.com/sites/mysitecollection', //required string
                                                        listName:'myList' //required string
                                                      })
                                                        .then(function(response){
                                                          console.log(response)
                                                          })
                    
                    }])

SPRESTListServices.getField()

Example:

myapp.controller('myController',[
                    '$scope',
                    'SPRESTListServices',
                    function($scope,$SPRESTListServices){
                      $scope.getFieldObj=SPRESTItemServices.getField({
                                                        siteUrl:'http://mySite.com/sites/mysitecollection', //required string
                                                        listName:'myList' //required string
                                                        GUID:'{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}' //required guid
                                                      })
                                                        .then(function(response){
                                                          console.log(response)
                                                          })
                    
                    }])

SPRESTListServices.getFields()

Example:

myapp.controller('myController',[
                    '$scope',
                    'SPRESTListServices',
                    function($scope,$SPRESTListServices){
                      $scope.getFieldObj=SPRESTItemServices.getFields({
                                                        siteUrl:'http://mySite.com/sites/mysitecollection', //required string
                                                        listName:'myList' //required string
                                                        
                                                      })
                                                        .then(function(response){
                                                          console.log(response)
                                                          })
                    
                    }])

##SPRESTUserServices --

SPRESTListServices.getCurrentUser()

Example:

myapp.controller('myController',[
                    '$scope',
                    'SPRESTUserServices',
                    function($scope,$SPRESTUserServices){
                      $scope.getFieldObj=SPRESTItemServices.getCurrentUser({
                                                        siteUrl:'http://mySite.com/sites/mysitecollection', //required string
                                                      })
                                                        .then(function(response){
                                                          console.log(response)
                                                          })
                    
                    }])

angular-spservicesrest-sharepoint's People

Contributors

noahwallace avatar

Watchers

James Cloos 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.