-
Working with CRM Bit Fields
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;// orcrmForm.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// orcrmForm.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 2,318 views2 responses to “Working with CRM Bit Fields”
-
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?
-
mitch June 20th, 2008 at 14:45
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
-



