2

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.load(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();
            console.log(proj);

            resources = currProj.get_projectResources();

            projContext.load(resources);


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

            console.log(resources);
        }

}

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) {

        console.log(error);

    }


}
0

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

projContext.load(projects);

Changing this to the following will make it work:

projContext.load(projects, 'Include(Id, Resources)');

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.