0

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.

2 Answers 2

3

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);
    }
}
3
  • Thanks for the reply. But this is the hard coded way. I would like to get all the template types using some existing property or method. This would help me to compare the value from the dropdown list. Commented Jun 11, 2014 at 11:00
  • I've updated my answer to address this. Commented Jun 11, 2014 at 11:14
  • Thanks a lot for the solution. Iterating through SP.ListTemplatType did the trick. :) Commented Jun 11, 2014 at 12:01
1

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);
1
  • Thanks Vadim for the quick reply. I am however looking to get the above values using an existing SP.ListTemplate method or property. Something like get_name()... Commented Jun 11, 2014 at 11:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.