1

I am using CSOM to traverse through Project Server 2013 resources on a project. I am checking if the resources are generic since I have written code logic based on that. I have a BA and PM generic resources that are part of a project that I added using the Build Team feature in Project Server. These resources show up with the Generic flag checked ON when viewing them in resource center. But programmatically the IsGenericResource flag is returning False.

Here is the code snippet (relevant code within **) :

public string ProcessGenericResources(ProjectContext pc, PublishedProject publishedproject)
{
    try
    {
            Boolean bStaffingRequestItemUpdated = false; // this will be set to True whenever a staffing list item is update
            string sResourceApproverAttr = ExceptionUtility.ReadKeyFromConfig(sResourceApproverKey);
            string sRet = "";
            DraftProject project;

            if (publishedproject.IsCheckedOut)
               project = publishedproject.Draft.IncludeCustomFields;
            else
               project = publishedproject.CheckOut().IncludeCustomFields;

             pc.Load(project, p => p.Name, p => p.Id);
             DraftProjectResourceCollection ProjectResources = project.ProjectResources;
             pc.Load(ProjectResources, list => list.Include(item => item.Name, item => item.Id, item => item.IsGenericResource));
             pc.ExecuteQuery();
              // For each generic resource, check if an item is already in the Staffing Request list. If not create one
              foreach (DraftProjectResource resource in ProjectResources)
              {
                 List<string> listRMsNotified = new List<string>(); // this is to keep track of RMs already notified
                 pc.Load(resource);
                 pc.ExecuteQuery();
                 **bool bGenericResource = resource.IsGenericResource;
         ExceptionUtility.LogMessage("Resource=> Name:" + resource.Name + " ID:" + resource.Id + " Is Generic Resource?: " + bGenericResource);**
GreenAsJade
  • 14,459
  • 11
  • 63
  • 98
  • Welcome to StackOverflow. I tweaked your post to fix the formatting of the code you submitted, and added the CSOM tag, in case some experts interested in that might be able to help. – GreenAsJade Oct 18 '14 at 00:21
  • GreenAsJade,Thanks for fixing the formatting and adding the CSOM ta. I found my answer – Madhu Lakshmikanthan Oct 18 '14 at 20:48

1 Answers1

1

I found the issue. Apparently ProjectResource is not the same as EnterpriseResource. For each ProjectResource in a Project you will need to find a match in the ProjectContext.EnterpriseResources collection. The record in EnterpriseResources collection shows the correct value in the IsGeneric attribute.