Read Task Level Lookup Type Custom Field using CSOM

Read Task Level Lookup Type Custom Field using CSOM Project Online

Read Task Level Lookup Type Custom Field using CSOM. In this post, I described you to Read Task Level Lookup Type custom field using CSOM. You can read None attribute and Lookup attribute custom field using CSOM. Now the below code will work perfectly for Without lookup and lookup type custom field. I will discuss in my next post to read resource type Custom Field.

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 ReadTaskLevelCustomFieldValueOnline()
        {
            string TaskCustomWithNoneAttributes = "03c97fa1-ab28-e611-80da-00155d1c4913";
            string TaskCustomWithLookupAttributes = "55feb301-b02b-e611-80da-00155d183410";
            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));
                ProjectCont.ExecuteQuery();
                foreach (PublishedProject pubProject in ProjectCont.Projects)
                {
                    if (pubProject.Name.Equals("Project Name"))
                    {
                        Console.WriteLine(pubProject.Name);
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("-----------------------");
                        foreach (var tsk in pubProject.Tasks)
                        {
                          
                            DateTime StartDate  = Convert.ToDateTime(tsk.Start).Date;
                            Console.WriteLine(tsk.Name);
                            Console.WriteLine(tsk.Start);
                            Console.WriteLine(tsk.Finish);
                            Console.WriteLine(tsk.Duration);
                            Console.WriteLine(tsk.PercentComplete + "%");                           
                            ProjectCont.Load(tsk.CustomFields);
                            ProjectCont.ExecuteQuery();
                            foreach (var CusFld in tsk.CustomFields)
                            {
                                if (CusFld.Id.Equals(new Guid(TaskCustomWithNoneAttributes)))//get Attribute none custom field
                                    Console.WriteLine("CustNone: " + tsk["Custom_03c97fa1ab28e61180da00155d1c4913"].ToString()); //Custom_(Your custom field(None attribute) without hyphen)
                                if (CusFld.Id.Equals(new Guid(TaskCustomWithLookupAttributes)))// get Attribute lookup field
                                {
                                    var lkup = ProjectCont.LoadQuery(ProjectCont.LookupTables.Where(x => x.Name == "LookupTableName")); //LookupTable Name associated with custom field
                                    ProjectCont.ExecuteQuery();
                                    foreach (LookupTable lktb in lkup)
                                    {
                                        ProjectCont.Load(lktb.Entries);
                                        ProjectCont.ExecuteQuery();
                                        foreach (LookupEntry en in lktb.Entries)
                                        {
                                            string cmp = ((string[])(tsk["Custom_55feb301b02be61180da00155d183410"]))[0].ToString(); //Custom_(Your custom field(Lookup attribute) without hyphen)
                                            string ent = en.Id.ToString().Replace("-", "");

                                            if (cmp == "Entry_" + ent)
                                            {
                                                Console.WriteLine("CustLookup: " + en.FullValue);
                                            }
                                        }
                                    }
                                }
                            }


                            Console.WriteLine("-----------------------");
                        }
                    }



                }
            }
        }

Some useful links are below-

Update Lookup Type Custom Field using CSOM

Update Task Level Custom Field using CSOM

Update Custom Field Value Using CSOM

Get Lookup Table Data using csom in Project Online


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 !!