none
Add local users to ProjectTeam using JSOM

    Pertanyaan

  • Hi All,

    I've written below code to add local users to the Project Team using JSOM, It has no syntax errors. But I cant see the changes in the project. 

    function ReadProjectResource()
    {
         projectContext = PS.ProjectContext.get_current();
         Allprojects = projectContext.get_projects();
         draftproject=Allprojects.getById(projectID).get_draft();
         ProjectResources = draftproject.get_projectResources();
         projectContext.load(ProjectResources);
         projectContext.executeQueryAsync(UpdateResource,errorHandler);
    }
    function UpdateResource()
    {
        debugger;
        try{
           // for(i=0;i<resources.length;i++){
                 var newResource = PS.ProjectResourceCreationInformation
                 newResource.set_id=createGuid();
                 newResource.set_name=resources[1];
                 draftproject.get_projectResources().add(newResource);
                draftproject.update();
           // }
            debugger;
            var queueJob = draftproject.publish(true);
            projectContext.waitForQueueAsync(queueJob, 60,function (response) {
                if (response !== 4) {
                   
                }
            });
        }

    I'm I missing anything here? Any help would be greatly appreciated.

    Thanks in Advance.

    Selasa, 04 September 2018 06.26

Jawaban

Semua Balasan

  • Hi All,

    I've written below code to add local users to the Project Team using JSOM, It has no syntax errors. But I cant see the changes in the project. 

    function ReadProjectResource()
    {
         projectContext = PS.ProjectContext.get_current();
         Allprojects = projectContext.get_projects();
         draftproject=Allprojects.getById(projectID).get_draft();
         ProjectResources = draftproject.get_projectResources();
         projectContext.load(ProjectResources);
         projectContext.executeQueryAsync(UpdateResource,errorHandler);
    }
    function UpdateResource()
    {
        debugger;
        try{
           // for(i=0;i<resources.length;i++){
                 var newResource = PS.ProjectResourceCreationInformation
                 newResource.set_id=createGuid();
                 newResource.set_name=resources[1];
                 draftproject.get_projectResources().add(newResource);
                draftproject.update();
           // }
            debugger;
            var queueJob = draftproject.publish(true);
            projectContext.waitForQueueAsync(queueJob, 60,function (response) {
                if (response !== 4) {
                   
                }
            });
        }

    I'm I missing anything here? Any help would be greatly appreciated.

    Thanks in Advance.


    Selasa, 04 September 2018 06.28
  • Hello,

    THis code sample will help you out:

    https://github.com/OfficeDev/Project-Samples/blob/master/O365-Project-Online-JavaScript-Samples/createproject.js

    From the code sample:

    // Creates a new local resource
    var new_resource_id = NewGuid();
    var new_resource = new PS.ProjectResourceCreationInformation();
    new_resource.set_name(resource_name);
    new_resource.set_id(new_resource_id);
    var project_resources_list = project.get_projectResources();
    var project_resource = project_resources_list.add(new_resource);

    Paul


    Paul Mather | Twitter | http://pwmather.wordpress.com | CPS | MVP | Downloads


    Selasa, 04 September 2018 08.24
    Moderator
  • Hi Paul,

    Thanks for your response.

    I was able to create  local resources while creating a new project. But when I add new local resources to the existing project the code is returning JOB STATE = 0 error. 

    Tried many ways but no luck. 

    1.  var queue_job = draft_project.publish(true);
     context.waitForQueueAsync(queue_job, 100, WaitForQueueCallback);

    2.  var queue_job = draft_project.update();
     context.waitForQueueAsync(queue_job, 100, WaitForQueueCallback);

    3.  var queue_job = draft_project.checkIn(true);      -->  // **it is not throwing error but changes are not reflecting.
     context.waitForQueueAsync(queue_job, 100, WaitForQueueCallback);


    Rabu, 05 September 2018 05.13
  • **** It worked when I use checkOut() instead of get_draft() method.

     Thanks Paul for your help.

    Rabu, 05 September 2018 09.02
  • Great to hear you have resolved it.


    Paul Mather | Twitter | http://pwmather.wordpress.com | CPS | MVP | Downloads

    Rabu, 05 September 2018 19.39
    Moderator