none
Add Enterprise resource to project team using CSOM in Project Server 2013 RRS feed

  • Question

  • Hi,

    I am trying to read the enterprise Resources in the Resource center and add any of them to a Project Team using CSOM. When I am trying to run my code, it is not giving any exception but the resource doees not get added to the Team pf the Project.

    Can anyone provide me some useful links where I could find code samples to add an enterprise resource to a team ?

    Thanks in advance.

    Regards,

    Divyang Agrawal

    Friday, August 9, 2013 9:27 AM

Answers

  • Hi,

    Thanks for the pointers.

    I was able to run the code successfully. There was an issue with the queue code I was using for running the update job. 

    Martin,

    I have used CSOM for the same and have not explored much on the JSOM front,although as you correctly said, the code is same for both the models.

    Sorry for the late reply.

    Regards,

    Divyang Agrawal

    • Marked as answer by Divyang Agrawal Wednesday, September 4, 2013 10:36 AM
    Wednesday, September 4, 2013 10:35 AM

All replies

  • Hi,

    Just for a checkpoint are you saving and publishing and then check-in back the Project after building your project team.

    Thanks !!!


    Sachin Vashishth MCTS

    Sunday, August 11, 2013 5:52 PM
  • Hi,

    I've been trying to figure out how to do a number of things with the JSOM recently, however the documentation is equally sparse when updating project data as it is with resource and team data. So far I've had to figure everything it out through trial and error mostly.

    Might help if you post a code sample?

    I've found that certainly for the JSOM the parameters required by each method are poorly documented so for example passing an invalid custom field name to an update method does not give any errors but obviously doesn't work.

    FYI, JSOM / CSOM should be the same syntax from my testing so far.


    Martin Laukkanen (Project Server Blog - www.nearbaseline.com/blog)

    Monday, August 12, 2013 12:09 AM
  • Hi,

    Thanks for the pointers.

    I was able to run the code successfully. There was an issue with the queue code I was using for running the update job. 

    Martin,

    I have used CSOM for the same and have not explored much on the JSOM front,although as you correctly said, the code is same for both the models.

    Sorry for the late reply.

    Regards,

    Divyang Agrawal

    • Marked as answer by Divyang Agrawal Wednesday, September 4, 2013 10:36 AM
    Wednesday, September 4, 2013 10:35 AM
  • Hi,

    Thanks for the pointers.

    I was able to run the code successfully. There was an issue with the queue code I was using for running the update job. 

    Martin,

    I have used CSOM for the same and have not explored much on the JSOM front,although as you correctly said, the code is same for both the models.

    Sorry for the late reply.

    Regards,

    Divyang Agrawal

    Hi Divyang,

    Can you please provide a code snippet of how did you solve this?

    Thanks,

    Gonzalo

    Friday, September 6, 2013 6:52 PM
  • Hi Gonzalo,

    Sorry for the late response. Below is the code I used. Kindly get back if you face any issues.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Microsoft.ProjectServer.Client;
    
    namespace AssignResourceToTeam
    {
        class CSOMTeam
        {
    
            private const string pwaPath = "your server URL";    // Change the path for Project Web App.
    
            // Set the Project Server client context.
            private static ProjectContext projContext;
            
           
    
            static void Main(string[] args)
            {
                projContext = new ProjectContext(pwaPath);
    
                Guid entResUid = new Guid("Resource Guid");
                Guid projectGuid = new Guid("Project Guid");
    
                // Get the list of enterprise resources in Project Web App.
                projContext.Load(projContext.EnterpriseResources);
                projContext.ExecuteQuery();
    
                int numResInCollection = projContext.EnterpriseResources.Count();
    
                if (numResInCollection > 0)
                {
    
                    var projectList = projContext.LoadQuery(
                       projContext.EnterpriseResources.Where(
                           ept => ept.Id == entResUid));
                    projContext.ExecuteQuery();
    
    
                    foreach (EnterpriseResource e in projectList)
                    {
                        if (e.Id == entResUid)
                        {
                            assignToTeam(projContext,projectGuid, e);
                        }
                    }
                               
                   
                }
            }
    
            private static void assignToTeam(ProjectContext projContext, Guid projectGuid, EnterpriseResource e)
            {
    
               // projContext = new ProjectContext(pwaPath);
                var projectList = projContext.LoadQuery(
                       projContext.Projects.Where(
                           ept => ept.Id == projectGuid));
                projContext.ExecuteQuery();
    
                if (projectList.Count() > 0)
                {
    
                    PublishedProject publishedProject = projectList.First();
                    DraftProject draftProject = publishedProject.CheckOut();
    
                    projContext.Load(draftProject.ProjectResources);
                    projContext.ExecuteQuery();
    
                    draftProject.ProjectResources.Count();
    
                    ProjectResourceCreationInformation resoDetails = new ProjectResourceCreationInformation();
                    resoDetails.Id = e.Id;
                               
    
                    DraftProjectResourceCollection resoColl = draftProject.ProjectResources;
                    resoColl.AddEnterpriseResource(e);
                  
                    projContext.EnterpriseResources.Update();
                    QueueJob qJob = projContext.Projects.Update();
                    JobState jobState = projContext.WaitForQueue(qJob, 30);
    
                    if (jobState == JobState.Success)
                    {
                        Console.WriteLine("\nResource addition Successful!");
                    }
                    else
                    {
                        Console.ForegroundColor = ConsoleColor.Yellow;
                        Console.WriteLine("\nThere is a problem in the queue. Timeout is {0} seconds.", 30);
                        Console.WriteLine("\tQueue JobState: {0}", jobState.ToString());
                        Console.ResetColor();
                    }
    
                }
            }
    
           
        }
    }
    

    Friday, September 20, 2013 10:48 AM
  • This is not working for Project Server 2016
    Sunday, June 4, 2017 4:44 AM
  • Yes, this is not working for project online. Have got the solution?

    I also want to add resource in project's Build Team.

    Tuesday, May 28, 2019 11:26 AM