Accessing the fields of a record

Entity objects contain all of the data associated with the fields of a record. When you need to know something about a field, you always start with the Entity object. In some cases, you can call methods of Entity to get the information you need. However, you can also use the Entity object to acquire a FieldInfo Object, which contains additional information about the field.

To acquire a FieldInfo object, call the GetFieldValue method.

To get the value stored in the FieldInfo object, call the GetValue method of the FieldInfo object.

To acquire a collection of FieldInfo objects, one for each field in the record, call the GetAllFieldValues method. (Note that GetAllFieldValues does not return the values in attachment fields.)

To get a list of the names of all fields, call the GetFieldNames method.

To get the type of data stored in the field, call the GetFieldType method.

To find out the field's behavior for the current action (mandatory, optional, or read-only), call the GetFieldRequiredness method.

Although you would normally use a FieldInfo object to access a field, there are situations where you must use methods of Entity.

To set the value of a field, call the SetFieldValue method.

To compare the new value with the old value of a field (if you previously updated the contents of a field), get the old value by calling the GetFieldOriginalValue method.

Note: Although you can get the behavior of a field using either an Entity object or FieldInfo object, you can only use the SetFieldRequirednessForCurrentAction method of Entity to set the field's behavior.

To modify fields that contain choice lists, use the methods of the Entity Object.

Task
Entity object method to call
To retrieve the list of permissible values in the field
GetFieldChoiceList
To get a constant indicating whether or not you can add additional items to the choice list.
GetFieldChoiceType
To add items to a choice list that can be modified
AddFieldValue
To delete items from a choice list that can be modified
DeleteFieldValue

As you update the fields of a record, the Entity object gives you several ways to keep track of all the modified fields. Because hooks can be written to modify other fields, calling the SetFieldValue method might result in more than one field being changed. For example, suppose you call SetFieldValue for Field X, and a field hook in Field X changes the value of Field Y.

Note: You should be careful to avoid creating an infinite loop (hooks that call each other).