Oct 22 2018
04:05 AM
- last edited on
Feb 06 2023
03:52 AM
by
TechCommunityAP
Oct 22 2018
04:05 AM
- last edited on
Feb 06 2023
03:52 AM
by
TechCommunityAP
I have a requirement to update Enterprise Resources in Project Online based on a condition and also need to update the Enterprise Custom Fields of Entity='Resource' related to it. I'm not able to find a connection between the two. What I have done so far:
1. Fetched Enterprise Resources from PWA. Enterprise Custom Fields related to Enterprise Resources are: Office, Level, SupervisorID, Division, Status, Supervisor, DepartmentNumber and LaborCategory
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 = "sreedevi@test.com"; //Email
enterpriseResource.Name = "Sreedevi H"; //FullNameprojContext.EnterpriseResources.Update();
projContext.ExecuteQuery();
}
}
}
}
I have tried below code to fetch the fields mentioned above but not able to fetch Enterprise Custom Fields Related to it:
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;
}
}
}
Any idea to find a relation between resource and custom fields will be helpful.