Modify App.js file and replace its content by following code:
'use strict';
var context = SP.ClientContext.get_current(); //App Web Context
var hostWebUrl, hostWebContext;
// This code runs when the DOM is ready and creates a context object which is needed to use the SharePoint object model
$(document).ready(function () {
//Get the URI decoded URLs.
hostWebUrl = decodeURIComponent(getQueryStringParameter("SPHostUrl"));
hostWebContext = new SP.AppContextSite(context, hostWebUrl);
});
// Retrieve a query string value.
function getQueryStringParameter(paramToRetrieve) {
var params = document.URL.split("?")[1].split("&");
for (var i = 0; i < params.length; i = i + 1) {
var singleParam = params[i].split("=");
if (singleParam[0] == paramToRetrieve) return singleParam[1];
}
}
//Create Content Type
function createContentType() {
if (hostWebContext != undefined && hostWebContext != null) {
var hostWeb = hostWebContext.get_web();
var contentTypeCollection = hostWeb.get_contentTypes();
//Get Document Content type by its Id. We will use Document Content Type as Base Content Type
//to create a new Content Type.
//Refer article for Ids of other Content Types.
var contentType = contentTypeCollection.getById("0x0101");
//Creating new Content Type
var newContentType = new SP.ContentTypeCreationInformation();
newContentType.set_name('Employee');
newContentType.set_group('Employee Details');
newContentType.set_description('Content Type for Employee Details.');
//Set Base Content Type
newContentType.set_parentContentType(contentType);
contentTypeCollection.add(newContentType);
context.load(contentTypeCollection);
context.executeQueryAsync(
function () {
alert('Content type created successfully on Host Web.');
},
function onContenttypeFailed(sender, args) {
alert('Content type creation failed. Error: ' + args.get_message() + '\n' + args.get_stackTrace());
});
}
}