ashkanyo
ashkanyo

Reputation: 132

Missing Fields on Create stage of the Dynamics CRM Plugin

Is there a way to access empty fields of a Target entity in the preoperation stage when it has not been populated by the user?

Upvotes: 0

Views: 582

Answers (2)

Dmitri
Dmitri

Reputation: 36

The short answer is no.
Target only contains attributes whose values were changed or deleted.
Images only contain attributes that were chosen in Plugin Registration Tool. But they still do not contain attributes with NULL values.
If you tell us more about your development, maybe we could suggest something else.

Upvotes: 2

ray gan
ray gan

Reputation: 198

You can access field by Entity.Contains() and Entity.GetAttributeValue<T>(). If field has not been populated, Entity.Contains() will return a false and Entity.GetAttributeValue<T>() will return a default(T).

Example:

// Entity.Contains(), use this to judge if entity contains a certains field.
if (targetEntity.Contains("yourfiledname"))
{
    var field = targetEntity.GetAttributeValue<string>("yourfiledname");
    if (string.IsNullOrEmpty(field))
    {
        // do your logic
    }
}
// Entity.GetAttributeValue<T>() this return a T or default(T).
var optionsetField = targetEntity.GetAttributeValue<OptionSetValue>("someoptionsetfield");
if (optionsetField != null)
{
    // do your logic
}

Upvotes: 1

Related Questions