The problem is that I can't get my resources out of the ProjectContext. I can get the project names but then something goes wrong and i get this warning:

Error: The collection has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested.

My code is:

function getProjects() {

    projects = projContext.get_projects();


    projContext.executeQueryAsync(projectSuccess, projectFail);


function projectFail(sender, args) {

    alert("Project Fail");

function projectSuccess() {

        var projEnum = projects.getEnumerator();

        while (projEnum.moveNext()) {

            var currProj = projEnum.get_current();
            var proj = currProj.get_id();

            resources = currProj.get_projectResources();


            projContext.executeQueryAsync((function () {resourceSucces(currProj, resources);})(currProj, resources),resourceFail);



function resourceFail(sender, args) {

    alert("Resource Fail");

function resourceSucces(currProj, resources) {

    try {

        var resourceEnum = resources.getEnumerator();

        while (resourceEnum.moveNext()) {

            var currRes = resourceEnum.get_current();
            enterpriseRes = currRes.get_enterpriseResource();
            console.log("RES " + currRes.get_id());

    catch (error) {




There are some minor issues with your code but the line that's killing you is


Changing this to the following will make it work:

projContext.load(projects, 'Include(Id, Resources)');
| improve this answer | |

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.