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,291 views
  • CRM 4.0 Workflow: Adding a timestamp to a field

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

    One of my current projects required that we have, more or less, an audit log for completion of tasks.  This can be easily accomplished using a CRM 4.0 workflow, using the following variables:

    image

    When the workflow is run, it will produce the following results:

    image 

    In this particular case, we are actually creating a task, then setting the Task Status to Completed so that it gets placed in the history for the record.

    Dynamics CRM, Workflow
    1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 4.00 out of 5)
    Loading ... Loading ...
    1,478 views