I got some JavaScript that is creating some Lists and Content Types. I am able to set the Content Types on the Lists, however I am not sure how I am suppose to set it as the Default Content Type. So I am pretty much just looking for code snippet that illustrates this.


Default Content Type is the First Content Type in the list of content types.

You can use set_uniqueContentTypeOrder for changing the order.

var context = SP.ClientContext.get_current();
var contentTypes = context.get_web().get_lists().getByTitle('ListTitle').get_contentTypes();
var rootFolder = context.get_web().get_lists().getByTitle('ListTitle').get_rootFolder();
context.load(rootFolder, 'ContentTypeOrder', 'UniqueContentTypeOrder');
context.executeQueryAsync(onSuccess, onFailed);

function onSuccess(){
    contentTypes = context.get_web().get_lists().getByTitle(current.ListTitle).get_contentTypes();
    var ctOrder = new Array();
    var enum = contentTypes.getEnumerator();
    while (enum.moveNext()) {
        //Populate ctOrder in your new order by making default content type as the first item
    context.executeQueryAsync(success, failed);

Source - https://cann0nf0dder.wordpress.com/2014/02/26/setting-default-content-types-for-listlibraries-using-javascript/

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.