【发布时间】:2018-12-07 04:13:10
【问题描述】:
我需要根据条件更新 Project Online 中的企业资源,还需要更新与之相关的Entity='Resource' 的企业自定义字段。我无法找到两者之间的联系。
到目前为止我做了什么:
从 PWA 获取的企业资源
。
using (ProjectContext projContext = new ProjectContext(projectUrl))
{
SecureString securePassword = new SecureString();
foreach (char character in password.ToCharArray())
securePassword.AppendChar(character);
projContext.Credentials = new SharePointOnlineCredentials(username, securePassword);
enterpriseResources = projContext.LoadQuery(projContext.EnterpriseResources);
projContext.ExecuteQuery();
if (enterpriseResources.Count() > 0)
{
foreach (EnterpriseResource resource in enterpriseResources)
{
if (!string.IsNullOrEmpty(resource.Email))
{
var enterpriseResource = projContext.EnterpriseResources.GetByGuid(resource.Id);
//var enterpriseResourceCustomFields = enterpriseResource.CustomFields.GetByGuid(resource.Id);
enterpriseResource.Email = "sahil@test.com"; //Email
enterpriseResource.Name = "Sahil Sharma"; //FullName
//enterpriseResource.Id = ""; //EmployeeID [Can't update, readonly]
//These below mentioned items are Enterprise Custom Fields related to Enterprise Resources but I'm not able to get it
//Office
//Level
//SupervisorID
//Division
//Status
//Supervisor
//DepartmentNumber
//LaborCategory
//Function
projContext.EnterpriseResources.Update();
projContext.ExecuteQuery();
}
}
}
}
什么没做:
无法获取与其相关的企业自定义字段:
我已经尝试过这个查询,但无法获取上面提到的确切字段:
foreach (EnterpriseResource resource in enterpriseResources)
{
if (!string.IsNullOrEmpty(resource.Email))
{
var pId = Guid.Parse("a5c8801f-d505-e811-a745-b0359f8878e9");
var customProject = projContext.LoadQuery(projContext.Projects.Where(p => p.Id == pId).Include(
p => p.Id,
p => p.Name,
p => p.IncludeCustomFields,
p => p.IncludeCustomFields.CustomFields,
P => P.IncludeCustomFields.CustomFields.IncludeWithDefaultProperties(
lu => lu.LookupTable,
lu => lu.LookupEntries
))
);
projContext.ExecuteQuery();
foreach (PublishedProject pubProj in customProject)
{
var projECFs = pubProj.IncludeCustomFields.CustomFields;
Dictionary<string, object> ECFValues = pubProj.IncludeCustomFields.FieldValues;
}
}
}
任何想法都会有助于找到它们之间的关系并获取。
【问题讨论】:
标签: c# sharepoint csom ms-project