更新与 PWA Online 中的企业资源相关的企业自定义域



我需要根据条件更新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;
}
}
}

任何想法都将有助于找到它们之间的关系并获取。

你需要:
1。从 projContext 获取自定义字段。
2. 获取映射"显示名称 - 内部名称"。
3. 通过自定义字段内部名称从字段值中获取自定义字段值。
4. 在企业资源上设置自定义字段值。

我认为你的代码必须是这样的:

projContext.Load(projContext.CustomFields);
projContext.ExecuteQuery();
var projectCustomFieldDisplayName = "My Project Custom Field Display Name";
var projectCustomField = projContext.CustomFields.FirstOrDefault(cf => cf.Name == projectCustomFieldDisplayName);
object projectCustomFieldValue = "";
var resourceCustomFieldDisplayName = "My Enterprise Resource Custom Field Display Name";
var resourceCustomField = projContext.CustomFields.FirstOrDefault(cf => cf.Name == resourceCustomFieldDisplayName);
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;
if (projectCustomField != null)
{
projectCustomFieldValue = ECFValues.Where(pair => pair.Key == projectCustomField.InternalName).FirstOrDefault().Value;
}
}
// Update enterprise resource custom field
if (resourceCustomField != null)
{
resource.SetCustomFieldValue(resourceCustomField.InternalName, projectCustomFieldValue);
enterpriseResources.Update();
}
}
}

相关内容

  • 没有找到相关文章

最新更新