Adding User Defined Fields (UDFs) in code

How to add a UDF to a PlanetTogether object in a customization

This small example illustrates how to write a method that adds a UDF to a given operation:

private const string c_customFieldString = "Custom Field";

private void AddUDFtoOperation(InternalOperation a_iOp, string a_value)
//Create and add UDF
UserField opUserField = new UserField(c_customFieldString, a_value, UserField.UDFTypes.String);

//UserFields property on the object must be set before adding the UDF
if (a_iOp.UserFields == null)
a_iOp.UserFields = new UserFieldList();



Let's take a closer look at the three steps necessary to add the UDF:

  1. First create an instance of a UserField. The constructor takes three parameters. The first one is a string to represent the name of the field, the second is an object to represent the value and the last is a UDFTypes enum to identify the  UDF value data type. UDFTypes includes the following enumerations: { String, Hyperlink, Integer, Long, Double, Decimal, Boolean, DateTime, TimeSpan }.
  2. Before adding the UDF, the UserFields property on the operation must be initialized. If it is null, adding the UDF will throw an exception; we can initialize it with a new instance of UserFieldsList to avoid this problem.
  3. Finally, simply use the Add method on the UserFields property and pass the UserField object created in the first step to complete the process.

Next Steps

Explore the following articles to learn all there is to know about customization projects in PlanetTogether:

Getting started with customizations

Advanced topics

Coming Soon...