6

I have been using the JSOM with SharePoint 2013 and am trying to get the content types of a list to iterate through, and am having no luck.

First, while the success handler is being reached, the oTargetCTypes variable never seems to be populated. Secondly, I occasionally get an exception thrown when a null id somewhere attempts to have the toString method called.

I see nothing wrong with this code, but if someone sees something I dont I would appreciate the assist!

function addIfPollList(listId, webId) {
this.optionListId = listId;
this.optionListTitle = listTitle;
this.optionWebId = webId;

this.clientContext = new SP.ClientContext.get_current();
this.oTargetList = clientContext.get_site().openWebById(this.optionWebId).get_lists().getById(optionListId);
this.oTargetCTypes = this.oTargetList.get_contentTypes();

this.clientContext.load(oTargetCTypes);
this.clientContext.executeQueryAsync(
Function.createDelegate(this, isPollListSuccessHandler),
Function.createDelegate(this, isPollListErrorHandler)
);
}

function isPollListSuccessHandler() {
cTypeEnumerator = this.oLists.getEnumerator();
}

function isPollListErrorHandler() {}
  • I don't know if this helps or not but does your app need full control? – Josey Oct 31 '13 at 20:06
4

In your success function you are trying to access oList which I guess is not correct. function addIfPollList loads content type in oTargetCType object, hence I believe it should enumerated in success function.

function addIfPollList(listId, webId) {
    this.optionListId = listId;
    this.optionListTitle = listTitle;
    this.optionWebId = webId;

    this.clientContext = new SP.ClientContext.get_current();
    this.oTargetList = clientContext.get_site().openWebById(this.optionWebId).get_lists().getById(optionListId);
    this.oTargetCTypes = this.oTargetList.get_contentTypes();

    this.clientContext.load(oTargetCTypes);
    this.clientContext.executeQueryAsync(
        Function.createDelegate(this, isPollListSuccessHandler),
        Function.createDelegate(this, isPollListErrorHandler)
    );
}

function isPollListSuccessHandler() {
    //cTypeEnumerator = this.oLists.getEnumerator();
    //I guess you need access this.oTargetCTypes as you are loading it in above function
    cTypeEnumerator = this.oTargetCTypes.getEnumerator();
}

function isPollListErrorHandler() {}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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