Update Lookup Type Custom Field Value using CSOM

Update Lookup Type Custom Field Value using CSOM

Update Lookup Type Custom Field Value using CSOM. Basically below is code for Update Lookup Type Custom Field Value using CSOM. If you need to update task level custom field using CSOM, Follow my post Update Task Level Custom Field using CSOM.

Note: Custom Field Value is set as (Custom_You custom field GUID without a hyphen). Let’s say your custom field GUID is 84b123af-e227e611-80d80015-5d1c7718. Now set is as (Custom_84b123afe227e61180d800155d1c7718) and Associated Lookup Entities as simple Entities ID. If you don’t know how to get Lookup Entities ID, Follow my post Get Lookup Table Data using csom in Project Online

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

Add  references in Solution


using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Principal;
using System.ServiceModel;
using System.Data;
using Microsoft.ProjectServer.Client;
using Microsoft.SharePoint.Client;
using System.Security;

namespace Update_Custom_Field_Using_CSOM
    class Program
        static string UserName = "UserName";
        static string Passwords = "Password";
        public static string OnlinePWA = "PWAPath";
        static void Main(string[] args)
        private static void UpdateLookupTypeCustomField()
            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);
                c => c.IncludeWithDefaultProperties(pr => pr.CustomFields));
                var projectColl = ProjectCont.LoadQuery(ProjectCont.Projects.Where(p => p.Name == "Anil Testing"));
                PublishedProject pubProj = projectColl.First();
                if (!pubProj.IsCheckedOut)
                    DraftProject projCheckedOut = pubProj.CheckOut();
                    projCheckedOut.SetCustomFieldValue("Custom_84b123afe227e61180d800155d1c7718", new object[] { "6766928a-e227-e611-80da-00155d1c9615" });

                    //Custom_84b123afe227e61180d800155d1c7718=Lookup type custom field GUID. Custom_(Your Lookup type GUID without hyphen).
                    //6766928a-e227-e611-80da-00155d1c9615= Lookup Entries ID which you want to set in your custom field.If you don't know how to get Lookup Entries ID follow my post(Get lookup type value using csom) link is below.
                    JobState jobState = ProjectCont.WaitForQueue(ProjectCont.Projects.Update(), 10);

Some Useful links,

Create Boolean Type Site Column using CSOM

Create DateTime Type Site Column using CSOM

Create Choice Type Site Column using CSOM

Remove Resource from Project Team using CSOM

Remove Resource from Project Task using CSOM

Add Enterprise Resource to Project Team using CSOM

Note: This is working code. If it helps you then share with your friends and like my Facebook page for the New post. 

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