Knowledge found and lost while working with Microsoft Dynamics CRM
RSS icon Home icon
  • Working with CRM Bit Fields

    Posted on May 22nd, 2008 mitch Print Print 2 comments

    Quite some time ago, I wrote a short article on using the Bit attribute type within CRM.

    Today, I thought I'd like to take some time to review some tips that may not be totally obvious when you first start working with Bit attributes.

    The method that you will use to interact with the Bit attribute will depend on how the attribute is displayed.  And, if you should change the format of the Bit Attribute, if could affect the way your code functions.

    Checkbox or Radio Button Formats

    If the Bit attribute is displayed as either a Checkbox or a Radio Button, you reference the Attribute's value as a boolean field

    Check for True or False:
    if (crmForm.all.new_mybitfield.DataValue)
    {
        // DataValue is true, do something interesting
    }
    else
    {
        // DataValue is false, do something interesting
    }
    Setting the Value:
    crmForm.all.new_mybitfield.DataValue = true;
    // or
    crmForm.all.new_mybitfield.DataValue = false;

    List Format

    The List format is actually converted into a Picklist with values of No and Yes.  Since it is a Picklist, we can't use the above code.  With this being the case, access and manipulation of the data is totally different.  Instead of a boolean value, the List format of a Bit Attribute uses an integer instead:

    NO = 0

    YES = 1

    Check for True or False:
    if (crmForm.all.new_mybitfield.DataValue == 0)
    {
        // The answer is NO
    }
    else
    {
        // The answer is YES.
    }
    Setting the Value:
    crmForm.all.new_mybitfield.DataValue = 0; // No
    // or
    crmForm.all.new_mybitfield.DataValue = 1; // Yes

     

    Attempting to assign a true or false value to a List-formatted Bit Attribute will result in an error dialog box being displayed.

    Well, that about covers it. If anyone has any further suggestions, please add a comment to the post.

    Customization, Dynamics CRM
    1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
    Loading ... Loading ...
    2,318 views
     

    2 responses to “Working with CRM Bit Fields”

    1. I see that CRM 4.0 has the ability to do radio buttons out of the box for the Bit type attribute. How do you convert it to a checkbox?

    2. Take a look at this article:
      http://blogs.infinite-x.net/2006/03/04/using-the-dynamics-crm-30-bit-attribute-type/

    Leave a reply