1

I have a calculated column which I have set to check if another column is blank or not.

I have a webservice which looks into this list and should return true or false if the column is empty or not. To simplify my code I have chosen to use the calculated column to easier determine the existence of data in the column.

However I've only found examples on how to return text, number, or dates when using a calculated field but not boolean.

I tried using bits (0 and 1), but when I try returning the calculated column as a boolean with either 0 or 1 I get the error "Specified cast is not valid".

[WebMethod]
public bool IsItTrue()
{
    try {
        // List query code blah blah
        return (bool)listItem[CalculatedColumn];
    }
    catch (Exception ex) {
        // Logging logic
    }
}

So how do I make my calculated column contain boolean values?

1

Found the answer. By using =ISBLANK([ColumnName]) and =NOT(ISBLANK([ColumnName])) and setting Calculated Column to return Yes/No values I was able to achieve what I wanted.

Update
Be aware that when you try to get the values from the column using the above setup the code will return Yes/No values.

So to check if the column contains "true" or "false",

var myCalculatedField = listItem.GetFormattedValue("ColumnName");
if (myCalculatedField == "Yes") 
    return true;
else 
    return false;

It works, yes. But it is highly unwanted if you are working on multilingual solutions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy