I have created a custom Content Type in a SharePoint App. I've had no problems making a list based off of this Content Type in the App Web.
Requirements of my project have changed and I'd like to create the list based off of this Content Type in the Host Web.
I'm not sure what approach to take to do this. I've created lists in the Host Web before. For example I have a function that makes an events list or a contacts list like so:
//____________________________Required function for accessing the host site's info.___________________________________
function getQueryStringParameter(param) {
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] == param) {
return singleParam[1];
}
}
}
//____________________________Create a list if one does not already exist_________________________
//Base on this http://sharepointnadeem.blogspot.com/2013/12/sharepoint-2013-apps-access-data-in.html
function createList(listToCreate, typeOfList)
{
// Create a SharePoint list with the name that the user specifies.
var hostUrl = decodeURIComponent(getQueryStringParameter("SPHostUrl"));
var hostContext = new SP.AppContextSite(currentContext, hostUrl);
var hostweb = hostContext.get_web();
var listCreationInfo = new SP.ListCreationInformation();
listCreationInfo.set_title(listToCreate);
if (typeOfList === "events")
{
listCreationInfo.set_templateType(SP.ListTemplateType.events);
}
else if (typeOfList === "contacts")
{
listCreationInfo.set_templateType(SP.ListTemplateType.contacts);
}
var lists = hostweb.get_lists();
var newList = lists.add(listCreationInfo);
currentContext.load(newList);
currentContext.executeQueryAsync(onListCreationSuccess, onListCreationFail);
}
function onListCreationSuccess() {
//alert("We've created a " + "list since one doesn't exist yet." );
}
function onListCreationFail(sender, args) {
//alert("We didn't create the list. Here's why: " + args.get_message());
}
I'm trying to figure out the modifications I need to make to this code to create lists based off of custom Content Types in the Host Web.