Posts

Showing posts from 2017

Create SharePoint List/Library using JSOM (JavaScript)

Use the below code to create a SharePoint document library using REST API. You can change the  ' set_templateType ' value  for creating list/library based on your requirement. //Create library using JSOM function createNewLibraryUsingJSOM() { var newListName = " Your New List/Library Name here "; SP.SOD.executeFunc(' SP.js ', 'SP.ClientContext', function() { //get site details var siteUrl = _spPageContextInfo.webAbsoluteUrl; var  clientContext = new SP.ClientContext(siteUrl); web = clientContext.get_web(); //create list object for new list var listCreationInfo = new SP.ListCreationInformation(); listCreationInfo.set_templateType(SP.ListTemplateType.documentLibrary); //SP.ListTemplateType.announcements listCreationInfo.set_title(newListName); listCreationInfo.set_quickLaunchOption(SP.QuickLaunchOptions.on); //get all lists & insert new list into it var  lists = web.get_lists(); list = lists

Deploy SharePoint workflows to SharePoint List/Library using JSOM

     Below code will deploy the workflow into SharePoint list/library. We need to use workflow definition id to deploy the workflow.      First function will get the workflow definition id based on the given workflow name & we will pass the workflow definition id to 2nd function to deploy into list/library. (Note this will return only 2013 workflows) //add the following workflowservices js files in document.ready function(as mentioned below) Or you can mentioned in your HTML file also. $(document).ready(function() { //load workflow js files SP.SOD.executeFunc(' sp.js ', ' SP.ClientContext' , function(){ SP.SOD.registerSod(' sp.workflowservices.js ', SP.Utilities.Utility.getLayoutsPageUrl(' sp.workflowservices.js ')); SP.SOD.executeFunc(' sp.workflowservices.js', "SP.WorkflowServices.WorkflowServicesManager" ); }); }); //give your existing workflow name, list/library name, new name for workflow var existingWor

Change default content type of SharePoint List/Library using JSOM (JavaScript)

Below code will change the default content type of the List/Library. It will reverse the order of available content types in the List. So our recently added content type will set into default content type. var listName = " Your List/Library name to change default content type " //Change default contend type (this code will reverse the current content type order, so our recently added content type will come first) function setAsDefaultContentType(listName) { var  c = SP.ClientContext.get_current(); var  folder = c.get_web().get_lists().getByTitle(listName).get_rootFolder(); c.load(folder, ' ContentTypeOrder '); c.executeQueryAsync( function () {  folder.set_uniqueContentTypeOrder(folder.get_contentTypeOrder().reverse());  folder.update();  c.executeQueryAsync( function  onSuccess()   { alert(' Content type changed!!! ');   },    function onFail()    { alert(' Error on default content typ

Add content type to SharePoint List/Library using REST API

Add content type to SharePoint List/Library using REST API Use this below code to add content type to SharePoint Library using REST API. For this you need to use the content type ID. Below function will get the content type ID from content type name & we will pass the content type id to next function which will update content type to list/library. var   varContentTypeName = " Your Content Type name "; var   Listname = " Your List name where you want to add content type "; //This will get the content type ID from content type Name function  getContentTypeID() { var deferred = $.Deferred();     var  isCurrentUserIsApprover = false ; var  serverURL = _spPageContextInfo.webAbsoluteUrl; var  listURL = String.format(" {0}/_api/web/AvailableContentTypes?$select=Name,Id,StringId&$filter=Name eq '"+varContentTypeName+"' ",serverURL); $.ajax({ url: listURL, type: " GET ", async: false, headers:

Create SharePoint List/Library using REST API

Use the below code to create a SharePoint document library using REST API. You can change the  'BaseTemplate' ID for creating list/library based on your requirment. function createNewLibraryUsingRest() { var newListName = "Your New Library Name"; var deferred = $.Deferred(); var serverURL = _spPageContextInfo.webAbsoluteUrl; var listURL = String.format ("{0}/_api/Web/Lists/",serverURL); $.ajax({ url: listURL, method: "POST", data: JSON.stringify({ '__metadata': { 'type': 'SP.List' }, 'AllowContentTypes': true, 'BaseTemplate': 101, //101 is for document library 'ContentTypesEnabled': true, 'Description': 'My list description', 'OnQuickLaunch': true, 'Title': newListName  }), headers: { "content-type": "application/json;odata=verbose", "X-Re