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.
If the Bit attribute is displayed as either a Checkbox or a Radio Button, you reference the Attribute's value as a boolean field
if (crmForm.all.new_mybitfield.DataValue)
{
// DataValue is true, do something interesting
}
else
{
// DataValue is false, do something interesting
}
crmForm.all.new_mybitfield.DataValue = true;
// or
crmForm.all.new_mybitfield.DataValue = false;
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
if (crmForm.all.new_mybitfield.DataValue == 0)
{
// The answer is NO
}
else
{
// The answer is YES.
}
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.
2 Responses
mark
20|Jun|2008 1I 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
20|Jun|2008 2Take a look at this article:
http://blogs.infinite-x.net/2006/03/04/using-the-dynamics-crm-30-bit-attribute-type/
Leave a reply