Skip to content

Instantly share code, notes, and snippets.

@princeppy
Forked from vman/createContentType.js
Created July 18, 2018 13:39
Show Gist options
  • Select an option

  • Save princeppy/81ae1a5df235bbc74d0dd58ee1f46047 to your computer and use it in GitHub Desktop.

Select an option

Save princeppy/81ae1a5df235bbc74d0dd58ee1f46047 to your computer and use it in GitHub Desktop.
createcontenttype: function () {
var dfd = $.Deferred();
var ctx = getContext();
var appctx = getAppContextSite(ctx);
var targetWeb = appctx.get_site().get_rootWeb();
var fields = targetWeb.get_fields()
var field = fields.getByInternalNameOrTitle(sitecolumnname);
ctx.load(fields);
ctx.load(field);
var ctci = constructContentTypeCreationInformation(contenttypeid, contenttypename)
var newType = targetWeb.get_contentTypes().add(ctci);
ctx.load(newType);
ctx.executeQueryAsync(succeed, fail);
function succeed(sender, args) {
var fieldRefs = newType.get_fieldLinks();
ctx.load(fieldRefs);
ctx.executeQueryAsync(
function () {
var flci = constructFLCI(field);
newType.get_fieldLinks().add(flci);
newType.update();
ctx.executeQueryAsync(function () { dfd.resolve(); },
function (sender, args) {
console.log("Content type creation failure: " + args.get_message());
dfd.reject();
});
},
function (sender, args) {
console.log("Content type creation failure: " + args.get_message());
dfd.reject();
});
}
function fail(sender, args) {
console.log("Content type creation failure: " + args.get_message());
dfd.reject();
}
return dfd.promise();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment