Adding Yes/No display for boolean fields in InforCRM (SalesLogix) datagrids

InforCRM has had the ability to define boolean entity properties as either True/False or Yes/No for a long time, however in a recent project, I found that displaying such an entity property as a bound field in a Data Grid would always display True or False (or nothing, if not set) regardless if it was set as a Yes/No data type.

In this project, the client wanted to display either Yes or No in the datagrid.  I also wanted to account for unset values, showing “No” if the underlying property was null.  To accomplish this, I turned to a Custom Format column in the datagrid.

Ryan previously posted a great article describing how to use of custom format columns to link to external sites, and I did something similar to display my desired values.

In the datagrid properties, I added a new Custom Format column, set the datafield to my boolean entity property and gave the method I was going to create a name of booleanDisplay in the Format Method Name property.  For the actual method, I included the following:

protected string booleanDisplay(object boolValue)
{
    bool val;
    if (boolValue != null)
    {
        val = (bool)boolValue;
    }
    else
    {
        val = false;
    }

    if (val)
    {
        return "Yes";
    }
    else
    {
        return "No";
    }
}

A couple notes on that code:  The method defined will always need an Object defined as the method parameter.  This required me to then check to see if the property had passed a null to the method.  If not, I cast the value to a new boolean variable. If it is null, I set the boolean variable to false.  Once I had my boolean variable, I simply had to evaluate it and return a “Yes” if true, or “No” if false.

All in all, this was a very simple way to evaluate a boolean entity property, and return Yes or No (or any value, really) based on the result, while also accounting for a potentially null value in the entity property.

Want content like this delivered to your inbox? Sign up for our newsletter!
ABOUT THE AUTHOR

Jason Buss

Jason is a senior application developer with Customer FX.

Submit a Comment

Your email address will not be published. Required fields are marked *