Last active
March 2, 2016 04:53
-
-
Save sksnips/9626120fc744fac28aea to your computer and use it in GitHub Desktop.
Code snippet to update the title and description for the SharePoint List
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Author: Shantha Kumar T | |
//set_title() and get_description() properties used to set the title and description to the list respectively | |
//get_title() and get_description() properties used to get the title and description to the list respectively | |
//Property used: SP.List.title and SP.List.description(sp.js) | |
//Supports SharePoint 2010 + and SharePoint Online | |
function UpdatelistTitle(listTitle) { | |
var clientContext = new SP.ClientContext(); | |
oList = clientContext.get_web().get_lists().getByTitle(listTitle); | |
oList.set_title('New List Title'); | |
oList.set_description('New List Title description'); | |
oList.update(); | |
clientContext.load(oList); | |
clientContext.executeQueryAsync( | |
Function.createDelegate(this, function() { | |
var listsInfo = ''; | |
listsInfo += oList.get_title() + '\t' + oList.get_description(); | |
//console.log(listsInfo.toString()); | |
alert(listsInfo.toString()); | |
}), | |
Function.createDelegate(this, function(sender, args) { | |
//console.log('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace()); | |
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace()); | |
})); | |
} | |
function injectMethod() { | |
var lisTitle = "Old List Title"; | |
UpdatelistTitle(lisTitle); | |
} | |
ExecuteOrDelayUntilScriptLoaded(injectMethod, "sp.js"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment