Read Project Enterprise Custom field value using CSOM
Hello Readers !
Thanks for reading this post.
Here I’m gonna show you how to read the Project level Enterprise custom field value using CSOM. The below code is for to read the text type custom field value but not the look up type. Will describe reading the look up type custom fields in another post separately.
Here is the piece of code that reads the Project level ECF value either using its Name (or) its ID.
ProjectContext context = new ProjectContext(<PwaURL>); context.Credentials = new SharePointOnlineCredentials(<userName>, <SecurePassword>);</pre> var projColl = context.LoadQuery(context.Projects .Where(p => p.Id == projectGuid) .Include( p => p.Id, p => p.Name, p => p.CustomFields, p => p.IncludeCustomFields, p => p.IncludeCustomFields.CustomFields ) ); context.ExecuteQuery(); //Reading Project ECF value using CF name string cfValue= string.Empty; try { foreach(var cf in pubProject.CustomFields) { if (cf.Name == "<CF Name>") { cfValue= pubProject.IncludeCustomFields.FieldValues[cf.InternalName].ToString(); break; } } } catch (System.Exception ex) { Response.Write("Error while reading CFs"); } //Reading ECF value using CF Internal ID string cfValue= string.Empty; try { foreach(var cf in pubProject.IncludeCustomFields.FieldValues) { if(cf.Key== "Custom_123ba782daa3e911b09200155d685937")//CF Internal ID { cfValue= cf.Value.ToString(); break; } } } catch (System.Exception ex) { Response.Write("Error while reading CFs"); } <pre>
Happy coding. 🙂
Recent Comments