Read project level lookup type custom field has multiple values using csom

Read project level lookup type custom field value has multiple values using CSOM

Read project level lookup type custom field Value value using CSOM. Read project level lookup type custom field value using CSOM. Also, read project level lookup type custom field has multiple values using CSOM. A custom field can have single value as well as multiple values. If you want select multiple values for a custom field, You need to check to Allow multiple values to be selected from the lookup table. Below is perfectly working code for the Read project level lookup type custom field using CSOM as well as multiple values.

If you don’t know to add references in your solutions then follow the post below

Add  references in Solution

[AdSense-A]

private static void ReadProjectLevelCustomFieldValueOnline()
        {

            using (ProjectContext ProjectCont = new ProjectContext(PWA))//PWA Url
            {
                SecureString passWord2 = new SecureString();
                foreach (char c in Pass.ToCharArray()) passWord2.AppendChar(c);
                ProjectCont.Credentials = new SharePointOnlineCredentials(UserName, passWord2);
                ProjectCont.Load(ProjectCont.Projects,
                c => c.IncludeWithDefaultProperties(pr => pr.CustomFields, pr => pr.Tasks, pr => pr.Owner, pr => pr.EnterpriseProjectType, pr => pr.IncludeCustomFields));
                ProjectCont.ExecuteQuery();
                foreach (PublishedProject pubProject in ProjectCont.Projects)
                {
                    if (pubProject.Name.Equals("Anil Testing"))
                    {
                        Console.WriteLine("Project Name :" + pubProject.Name + "");
                        Console.WriteLine("Owner :" + pubProject.Owner.LoginName);
                        Console.WriteLine("Start Date :" + pubProject.StartDate);
                        Console.WriteLine("Finish Date :" + pubProject.FinishDate);
                        Console.WriteLine("EPT :" + pubProject.EnterpriseProjectType.Name);
                        foreach (var item in pubProject.IncludeCustomFields.FieldValues)// read custom fields value
                        {
                            string k = item.Key.ToString();

                            if (k == "Custom_1960fc06a615e51180ca00155d186a12")//read custom field None attribute
                            {
                                Console.WriteLine("Client :" + item.Value);
                            }
                            if (k == "Custom_84b123afe227e61180d800155d1c7718")//read custom field lookup attribute 
                            {
                                var lookup = ProjectCont.LoadQuery(ProjectCont.LookupTables.Where(x => x.Name == "Department"));
                                ProjectCont.ExecuteQuery();
                                string LookupTypeCustomFieldValue = string.Empty;
                                foreach (LookupTable tb in lookup)
                                {
                                    ProjectCont.Load(tb.Entries);
                                    ProjectCont.ExecuteQuery();
                                    foreach (LookupEntry en in tb.Entries)
                                    {
                                        for (int i = 0; i < ((string[])(item.Value)).Count(); i++)
                                        {
                                            string cmp = ((string[])(item.Value))[i].ToString();
                                            string ent = en.Id.ToString().Replace("-", "");
                                            if (cmp == "Entry_" + ent)
                                            {
                                                LookupTypeCustomFieldValue += en.FullValue;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

 


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

error: Content is protected !!