Question

I am trying to create a new list (based on a dropdown menu selection) using JavaScript Client Side Object Model.

var typeList = "SP.ListTemplateType." +listTemplateType;
listCreationInfo.set_templateType(typeList);

The value of variable "listTemplateType" is from the dropdown control.

The problem is that these values are the normal list template values such as "Announcements", "DocumentLibrary" and etc. And these values give an error "input format is not correct".

E.g listCreationInfo.set_templateType(SP.ListTemplateType.DocumentLibrary);

However when I enter the SP.ListTemplateType enums (http://msdn.microsoft.com/en-us/library/office/ee549420%28v=office.14%29.aspx) such as announcements,documentLibrary etc, the list is created successfully.

E.g listCreationInfo.set_templateType(SP.ListTemplateType.documentLibrary);


I am also not able to find a property to obtain these enums - http://msdn.microsoft.com/en-us/library/office/jj247105%28v=office.15%29.aspx

Is there any way to get all the SP.ListTemplate types using an existing SP.ListTemplate method or property? Methods such as get_listTemplateTypeKind() are not giving the desired values in the correct format.

Was it helpful?

Solution

You can access the members of an enumeration (or any JavaScript object for that matter) using the C# indexer syntax. So the code you want would be something like:

var typeList = SP.ListTemplateType["announcements"];
listCreationInfo.set_templateType(typeList);

You can use a for loop to iterate all of the property values of the enumeration.

var message = $('#message');
message.text("SP.ListTemplateType members");
for (var prop in SP.ListTemplateType) {
    var value = SP.ListTemplateType[prop];
    if (typeof value == "number") {
        message.append("<br/>");
        message.append(prop + " " + value);
    }
}

OTHER TIPS

As you correctly noticed you could access ListTemplateType in JSOM like this:

var docLibType = SP.ListTemplateType.documentLibrary;

or

var docLibType = SP.ListTemplateType['documentLibrary'];

SP.ListTemplateType is enum type declared in sp.js library:

SP.ListTemplateType = function() {}
SP.ListTemplateType.prototype = {
    invalidType: -1, 
    noListTemplate: 0, 
    genericList: 100, 
    documentLibrary: 101, 
    survey: 102, 
    links: 103, 
    announcements: 104, 
    contacts: 105, 
    events: 106, 
    tasks: 107, 
    discussionBoard: 108, 
    pictureLibrary: 109, 
    dataSources: 110, 
    webTemplateCatalog: 111, 
    userInformation: 112, 
    webPartCatalog: 113, 
    listTemplateCatalog: 114, 
    xmlForm: 115, 
    masterPageCatalog: 116, 
    noCodeWorkflows: 117, 
    workflowProcess: 118, 
    webPageLibrary: 119, 
    customGrid: 120, 
    solutionCatalog: 121, 
    noCodePublic: 122, 
    themeCatalog: 123, 
    dataConnectionLibrary: 130, 
    workflowHistory: 140, 
    ganttTasks: 150, 
    meetings: 200, 
    agenda: 201, 
    meetingUser: 202, 
    decision: 204, 
    meetingObjective: 207, 
    textBox: 210, 
    thingsToBring: 211, 
    homePageLibrary: 212, 
    posts: 301, 
    comments: 302, 
    categories: 303, 
    facility: 402, 
    whereabouts: 403, 
    callTrack: 404, 
    circulation: 405, 
    timecard: 420, 
    holidays: 421, 
    imeDic: 499, 
    externalList: 600, 
    issueTracking: 1100, 
    adminTasks: 1200, 
    healthRules: 1220, 
    healthReports: 1221
}
SP.ListTemplateType.registerEnum('SP.ListTemplateType', false);
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top