4

I've spent a lot of time Googling and MSDNing on this topic and then stopped at the set_uniqueContentTypeOrder method.

This method will take an array of Content Type IDs and change the "New Item" sequence of the Content Types in your list.

But I can not make it work. Every time I call this method on my list's root folder, I always get an error message says "something is wrong". And when I dig into the log file for the detail, I can only see a "Null reference" error message.

So, does anyone know how to set a List's Default Content Type (order) by using Javascript? Thanks a lot!

2

This example will reverse the order, works for me:

var c = SP.ClientContext.get_current();
var folder = c.get_web().get_lists().getByTitle(<list title>).get_rootFolder();
c.load(folder, 'ContentTypeOrder');
c.executeQueryAsync(function() {
  folder.set_uniqueContentTypeOrder(folder.get_contentTypeOrder().reverse()); 
  folder.update();
  c.executeQueryAsync();
});
  • Hi eirikb, thanks! It does changes the default content type (order). But weird things happened: Once I added any columns from the 'new' default content type, the AllItems.aspx page will show an error message that "unable to display this web part." Any clue? – Jony Apr 16 '14 at 8:28
  • 1
    OK, I have figured it out: The new content type has the title column which conflicts with the default Item Title column. Once I removed the new content type ID column from the default view, it works now. – Jony Apr 16 '14 at 8:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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