web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How to cast a "Two Options" field to a bool type C#?

(0) ShareShare
ReportReport
Posted on by

I've added a Two Option field to a Form and now I'm reading back the value.

This is what I'm trying in order to read back the attribute value, first checking that the field exists them attempting a cast to bool. But there is a syntax error on the line where I try to get the attribute value - "(bool)contact.Attributes"



                        bool feeDeleted = contact.Attributes.ContainsKey("vs_feedeleted") ? (bool)contact.Attributes["vs_feedeleted"]




Does anyone know how to cast the Two Option field's value to a bool type in C#?

67053.2.PNG

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Community Member Profile Picture
    on at

    Hi bvarley ,

    if I am not wrong , you must complete your Conditional Expression. I hope this is the error.

    bool feeDeleted = contact.Attributes.ContainsKey("vs_feedeleted") ? (bool)contact.Attributes["vs_feedeleted"]:false;

  • Suggested answer
    Community Member Profile Picture
    on at

    use contact.GetAttributeValue<bool>("vs_feedeleted")

  • Community Member Profile Picture
    on at

    I'm trying contact.GetAttributeValue<bool>("vs_feedeleted") as I need to get the current value of the Two Option field.

    Does this code achieve the same thing? What's the difference?

    bool feeDeleted = contact.Attributes.ContainsKey("vs_feedeleted") ? (bool)contact.Attributes["vs_feedeleted"]:false;

  • Community Member Profile Picture
    on at

    i doesn't use first one. But i think both are same.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
ScottDurow Profile Picture

ScottDurow 2

#2
GJones Profile Picture

GJones 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans