How To Set Column Order in SharePoint Document Library 2013/2016 using CSOM?

Hello SharePointers,

In this blog, I will give you piece of CSOM code to set column order in SharePoint document library.

 

var ctx = new SP.ClientContext.get_current();
var list = ctx.get_web().get_lists().getByTitle(‘Custom┬áList’);

var listContentTypes;

listContentTypes = list.get_contentTypes();

ctx.load(listContentTypes);

ctx.executeQueryAsync(get_contentTypes_success, onFailure);

function get_contentTypes_success() {
var itemContenTypes = listContentTypes.getItemAtIndex(0);
var itemContenTypeFieldLink = itemContenTypes.get_fieldLinks();
itemContenTypeFieldLink.reorder([‘Employee_x0020_Number’, ‘Title’]);
itemContenTypes.update(false);

ctx.executeQueryAsync(field_reorder_success, onFailure);
}

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

function field_reorder_success() {
console.log(“Success”);
}

Happy SharePointing folks ­čÖé

Leave a Reply

Your email address will not be published. Required fields are marked *