Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Suggested answer

Reading optionset value if it s null return null

(0) ShareShare
ReportReport
Posted on by 595

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

  • Suggested answer
    Bipin D365 Profile Picture
    28,981 Moderator on at
    RE: Reading optionset value if it s null return null

    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.

    If found helpful, Please mark my answer verified.

  • Suggested answer
    Filipe Relvas Profile Picture
    on at
    RE: Reading optionset value if it s null return null

    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! 

  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at
    RE: Reading optionset value if it s null return null

    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.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
Siv Sagar Profile Picture

Siv Sagar 149 Super User 2025 Season 1

#2
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 61 Most Valuable Professional

#3
Daivat Vartak (v-9davar) Profile Picture

Daivat Vartak (v-9d... 53 Super User 2025 Season 1

Overall leaderboard

Product updates

Dynamics 365 release plans