我正在使用CSOM遍历项目中的Project Server 2013资源。我正在检查资源是否是通用的,因为我已经基于此编写了代码逻辑。我有一个BA和PM通用资源,它是我使用Project Server中的Build Team功能添加的项目的一部分。在资源中心查看Generic标志时,这些资源会显示为ON。但是,IsGenericResource
标志以编程方式返回False
。
以下是代码段(**中的相关代码):
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);**
答案 0 :(得分:1)
我发现了这个问题。显然,ProjectResource与EnterpriseResource不同。对于项目中的每个ProjectResource,您需要在ProjectContext.EnterpriseResources集合中找到匹配项。 EnterpriseResources集合中的记录在IsGeneric属性中显示正确的值。