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 type'); })
});
}

Comments

Popular posts from this blog

Add content type to SharePoint List/Library using REST API

Upload Single/Multiple file by using the REST API and jQuery SharePoint 2013

A type named 'SP.Data. could not be resolved by the model error