Update Enterprise Custom Fields related to Enterprise Resources in PWA Online

%3CLINGO-SUB%20id%3D%22lingo-sub-276285%22%20slang%3D%22en-US%22%3EUpdate%20Enterprise%20Custom%20Fields%20related%20to%20Enterprise%20Resources%20in%20PWA%20Online%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-276285%22%20slang%3D%22en-US%22%3E%3CP%3EI%20have%20a%20requirement%20to%20update%20Enterprise%20Resources%20in%20Project%20Online%20based%20on%20a%20condition%20and%20also%20need%20to%20update%20the%20Enterprise%20Custom%20Fields%20of%20Entity%3D'Resource'%20related%20to%20it.%20I'm%20not%20able%20to%20find%20a%20connection%20between%20the%20two.%20What%20I%20have%20done%20so%20far%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E1.%20Fetched%20Enterprise%20Resources%20from%20PWA.%20Enterprise%20Custom%20Fields%20related%20to%20Enterprise%20Resources%20are%3A%20Office%2C%20Level%2C%20SupervisorID%2C%20Division%2C%20Status%2C%20Supervisor%2C%20DepartmentNumber%20and%20LaborCategory%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CBLOCKQUOTE%3E%3CP%3Eusing%20(ProjectContext%20projContext%20%3D%20new%20ProjectContext(projectUrl))%3CBR%20%2F%3E%7B%3CBR%20%2F%3E%26nbsp%3B%20%26nbsp%3B%20SecureString%20securePassword%20%3D%20new%20SecureString()%3B%3CBR%20%2F%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3Eforeach%20(char%20character%20in%20password.ToCharArray())%3CBR%20%2F%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3EsecurePassword.AppendChar(character)%3B%3C%2FP%3E%3CP%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3EprojContext.Credentials%20%3D%20new%20SharePointOnlineCredentials(username%2C%20securePassword)%3B%3CBR%20%2F%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3EenterpriseResources%20%3D%20projContext.LoadQuery(projContext.EnterpriseResources)%3B%3CBR%20%2F%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3EprojContext.ExecuteQuery()%3B%3C%2FP%3E%3CP%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3Eif%20(enterpriseResources.Count()%20%26gt%3B%200)%3CBR%20%2F%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%7B%3CBR%20%2F%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3Eforeach%20(EnterpriseResource%20resource%20in%20enterpriseResources)%3CBR%20%2F%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%7B%3CBR%20%2F%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3Eif%20(!string.IsNullOrEmpty(resource.Email))%3CBR%20%2F%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%7B%3CBR%20%2F%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3Evar%20enterpriseResource%20%3D%20projContext.EnterpriseResources.GetByGuid(resource.Id)%3B%3CBR%20%2F%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3Evar%20enterpriseResourceCustomFields%20%3D%20%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3EenterpriseResource.CustomFields.GetByGuid(resource.Id)%3B%3CBR%20%2F%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3EenterpriseResource.Email%20%3D%20%22sreedevi%40test.com%22%3B%20%2F%2FEmail%3CBR%20%2F%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3EenterpriseResource.Name%20%3D%20%22Sreedevi%20H%22%3B%20%2F%2FFullName%3C%2FP%3E%3CP%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3EprojContext.EnterpriseResources.Update()%3B%3CBR%20%2F%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3EprojContext.ExecuteQuery()%3B%3CBR%20%2F%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%7D%3CBR%20%2F%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%7D%3CBR%20%2F%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%7D%3CBR%20%2F%3E%7D%3C%2FP%3E%3C%2FBLOCKQUOTE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20tried%20below%20code%20to%20fetch%20the%20fields%20mentioned%20above%20but%20not%20able%20to%20fetch%20Enterprise%20Custom%20Fields%20Related%20to%20it%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CBLOCKQUOTE%3E%3CP%3Eforeach%20(EnterpriseResource%20resource%20in%20enterpriseResources)%3CBR%20%2F%3E%7B%3CBR%20%2F%3E%26nbsp%3B%20%26nbsp%3B%20if%20(!string.IsNullOrEmpty(resource.Email))%3CBR%20%2F%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%7B%3CBR%20%2F%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3Evar%20pId%20%3D%20Guid.Parse(%22a5c8801f-d505-e811-a745-b0359f8878e9%22)%3B%3CBR%20%2F%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3Evar%20customProject%20%3D%20projContext.LoadQuery(projContext.Projects.Where(p%20%3D%26gt%3B%20p.Id%20%3D%3D%20%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3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FSPAN%3Ep%20%3D%26gt%3B%20p.IncludeCustomFields.CustomFields%2C%3CBR%20%2F%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3EP%20%3D%26gt%3B%20P.IncludeCustomFields.CustomFields.IncludeWithDefaultProperties(%3CBR%20%2F%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3Elu%20%3D%26gt%3B%20lu.LookupTable%2C%3CBR%20%2F%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3Elu%20%3D%26gt%3B%20lu.LookupEntries)))%3B%3C%2FP%3E%3CP%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3EprojContext.ExecuteQuery()%3B%3C%2FP%3E%3CP%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3Eforeach%20(PublishedProject%20pubProj%20in%20customProject)%3CBR%20%2F%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%7B%3CBR%20%2F%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3Evar%20projECFs%20%3D%20pubProj.IncludeCustomFields.CustomFields%3B%3CBR%20%2F%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3EDictionary%3CSTRING%3E%20ECFValues%20%3D%20pubProj.IncludeCustomFields.FieldValues%3B%3CBR%20%2F%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%7D%3CBR%20%2F%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%7D%3CBR%20%2F%3E%7D%3C%2FSTRING%3E%3C%2FP%3E%3C%2FBLOCKQUOTE%3E%3CP%3EAny%20idea%20to%20find%20a%20relation%20between%20resource%20and%20custom%20fields%20will%20be%20helpful.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-276285%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EOffice365General%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Highlighted
Frequent Visitor

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"; //FullName

                projContext.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.

0 Replies