Reputation: 132
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
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
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