Skip to content

Instantly share code, notes, and snippets.

@sksnips
Last active March 2, 2016 04:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sksnips/9626120fc744fac28aea to your computer and use it in GitHub Desktop.
Save sksnips/9626120fc744fac28aea to your computer and use it in GitHub Desktop.
Code snippet to update the title and description for the SharePoint List
//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