0

I am trying to use a client context and load in userproperties and a list in the same success method. However I am having a problem as I get an error saying my listitems are undefined. Here is my code :

NBSProfileInfo.NewsPersonalisation = (function () {

var MyProperties,

    getMyNewsChoices = function () {

        // Get the current client context and PeopleManager instance.
        var clientContext = SP.ClientContext.get_current();

        var peopleManager = new SP.UserProfiles.PeopleManager(clientContext);

    // Get user properties for the target user.
    // To get the PersonProperties object for the current user, use the
    // getMyProperties method.
    MyProperties = peopleManager.getMyProperties();


    // Load the PersonProperties object and send the request.
    clientContext.load(MyProperties);

    var editablePropertiesList = clientContext.get_site().get_rootWeb().get_lists().getByTitle('EditableProperties'),
    camlQueryEP = new SP.CamlQuery(),
    collListItemsEP;


    collListItemsEP = editablePropertiesList.getItems(camlQueryEP);




    clientContext.load(collListItemsEP);
    clientContext.executeQueryAsync(getMyNewsChoicesSuccess, getMyNewsChoicesFail);
    },

    getMyNewsChoicesSuccess = function () {

    var listItemEnumeratorlistReadyEP = collListItemsEP.getEnumerator(),
    countEP = collListItemsEP.get_count(),
    EPItem;
    var listTitle = [];

    while (listItemEnumeratorlistReadyEP.moveNext()) {

        EPItem = listItemEnumeratorlistReadyEP.get_current();
        listTitle.push(footerListItem.get_item('Title'));

    }

this is the part of my code that is not working it says collListItemsEP is undefined How can I make it so I can use them in the same success method. Or at least be able to use the output of my list into the success method of the user properties people manager.

7
  • I get the same error
    – jimmywhizz
    Commented Aug 20, 2014 at 11:31
  • var listItemEnumeratorlistReadyEP = collListItemsEP.getEnumerator()
    – jimmywhizz
    Commented Aug 20, 2014 at 11:32
  • 'collListItemsEP' is undefined
    – jimmywhizz
    Commented Aug 20, 2014 at 11:33
  • doesn't change anything
    – jimmywhizz
    Commented Aug 20, 2014 at 11:40
  • var editablePropertiesList = clientContext.get_site().get_rootWeb().get_lists().getByTitle('EditableProperties'), camlQueryEP = new SP.CamlQuery(), collListItemsEP;
    – jimmywhizz
    Commented Aug 20, 2014 at 12:44

1 Answer 1

0

You need to declare the collListItemsEP variable globally so that it'll be defined when used in the success callback.

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.