Posts

SharePoint Dynamic CRUD Operations using Rest API

SharePoint Dynamic CRUD Operations using Rest API Use the below code for dynamic CRUD operations. You can create CRUD.js file using the below code & call the crud operations from different places by passing different parameters. //<<<<<<<<<<<<<<<<<<<<<<<< NOTE - Follow the below instructions to call the CURD Functions >>>>>>>>>>>>>>>>>>>>>>>>>      //-----------------createItem('ListName',['ColumnName1','ColumnName2',...],['Value1','Value2',...]);-------------          //Example: createItem('testlist',['Title','Name','Age'],['ABC','XYZ',10]);           //-----------------updateItem('ListName',itemID,['ColumnName1','ColumnName2',...],['Value1','Value2',...]);------          //Exampl...

Enable SharePoint Read only columns of List/Library

Image
Enable SharePoint Read only columns of List/Library Some times under SharePoint List/Library settings columns are not enabled(Greyed out) to edit or delete. Using below jsom code we can enable the readonly columns. For this you need to proide below inputs 1.List Name 2.ContentType ID whitch the column is associated 3.Any substring of column name (example: If column name is 'Country Name' -> you can type 'Country') Here we can get the content type id from list settings if we click content type from URL we can get content type ID We need to add Script editor web part & insert the below code. < html > AnySubStringofColumnName: < input type = "text" id = "txtColName" />< br />< br /> ListName: < input type = "text" id = "txtListName" />< br />< br /> ContentTypeID: < input type = "text" id = "txtContentType" />< br />< ...

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()    ...

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