0

I am trying to change the title of one of the document libraries programatically with JSOM.

This is the code but it is not working... any ideas?

function UpdateDocumentLibraryName(oNewWebsite) {

var oList = oNewWebsite.get_lists().getByTitle('Documentos');

oList.set_title = 'Contenidos Pedagogia';
oList.update();
context.load(oList);
}

2 Answers 2

2

You are missing SP.ClientContext.executeQueryAsync method that performs the changes.

How to update List title via JSOM:

var oldListTitle = 'Documents';
var newListTitle = 'Public Documents';

var context = SP.ClientContext.get_current();
var list = context.get_web().get_lists().getByTitle(oldListTitle);   
list.set_title(newListTitle);
list.update();
context.executeQueryAsync(
function(){
  console.log('List Title has been updated');    
}, 
function(sender,args){
  console.log(args.get_message());    
});    
1
  • context.load(list); should be called before context.executeQueryAsync? Commented Aug 28, 2016 at 7:09
1

try this code

function UpdateDocumentLibraryName(oNewWebsite) {

var oList = oNewWebsite.get_lists().getByTitle('Documentos');

oList.set_title('Contenidos Pedagogia');
oList.update();
context.load(oList);
}

If above not worked then check this post: http://sharepointreffer.blogspot.com/2013/08/updateedit-list-title-using-javascript.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.