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

Notifications

Announcements

No record found.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans