i'm retrieving optionset value through plugin on create of record i'm calling the plugin...
my problem is i have option set field with optional (not mandatory) but if it is not selected any values... then i'm getting exception... if i selected any option then it is returning value....
is there any suggestion to this, i need to get null if optionset is not selected
Hi,
You can also check if entity object contains that attribute and then get the value.
int optionSetValue=-1;
if(entity.Attributes.Contains("fieldschemaname") && entity["fieldschemaname"]!=null)
optionSetValue=((OptionSetValue)entity["fieldschemaname"]).Value;
Now if field is null then it will return -1 else it will return the optionset value selected by the user on UI.
Hi Abhilash,
When you create or update a record and trigger a Plugin, the Plugin context usually comes with the attributes that were filled or changed by the user i.e. attributes are seen as dirty.
Any other attributes will not be part of the context, hence why they come as null, but can be obtained through an Organization Service request using the GUID of the Entity record that triggered it.
If you do have the necessity to get the Option Value even if it's not mandatory I would suggest one of two options:
Hope this helps!
Hello,
I believe you use code that is similar to following:
var optionsetValue = (OptionSetValue)entity["optionsetfieldname"];
in order to resolve your issue try to use following syntax instead:
var optionsetValue = entity.GetAttributeValue<OptionSetValue>("optionsetfieldname");
If there will be no value - it will return null.
Siv Sagar
149
Super User 2025 Season 1
Muhammad Shahzad Sh...
61
Most Valuable Professional
Daivat Vartak (v-9d...
53
Super User 2025 Season 1