1

How do I set fields in Content Type to hidden? This run below runs but the field didn't change. Also how can I specify which field I want to set?

var x = function () {
    var listContentTypes;
    var ctx = new SP.ClientContext.get_current();
    var list = ctx.get_web().get_lists().getByTitle("Risks");
    listContentTypes = list.get_contentTypes();
    ctx.load(listContentTypes);
    ctx.executeQueryAsync(GetContentTypes_success, failure);

    function GetContentTypes_success() {

        var itemContenType = listContentTypes.getItemAtIndex(0);
        var itemContenTypeFieldLink = itemContenType.get_fieldLinks();

        // Hide field 
        var field = itemContenTypeFieldLink.get_itemAt(0)
        field.set_hidden(true)
        field.update()

        itemContenType.update(false);
        ctx.executeQueryAsync(success, failure);
    }

    function failure(sender, args) {
        console.log(args.get_message());
    }

    function success() {
        console.log("Completed");
    }
};
  • I'm no coder, but you should be able to do this by the SP menus. Go in list or document library settings / select your content type / select the field within the content type / select 'hidden' in the column settings. But judging by your array of gold and silver medals I assume you have a reason for wanting to do this programatically. – Tally Oct 2 '17 at 8:52

Your Answer

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

Browse other questions tagged or ask your own question.