Need help regarding True/False if-statements

Hi!

So I currently have 2 columns: Date of Invoice (reference column) and Lessons Billed (toggle). Under Lesson Billed? I have this formula:

if $Date_of_Invoice == “” or $Date_of_Invoice == None:
return False # This is indented, realized it’s not showing the indentation on the forum
return True

The column should apply only on changes to: Date of Invoice.

This currently seems to work for when I apply a date, the toggle switches to True. However, when I remove the date, it still remains True. How can I update it so that way it returns False?

Here’s a small video clip to show my issue:

Hi Diana.

This certainly looks like a bug since your formula is correct and it should be treating empty references as equal to None.

As a workaround, what you can try is changing your formula to the following, where you’ll want to change Invoice_Date to the column name in the referenced table that holds the invoice dates:

if $Date_of_Invoice.Invoice_Date is None or $Date_of_Invoice.Invoice_Date == "":
  return False
return True
2 Likes

@georgegevoian’s answer should work, and I think I can explain what you are seeing.

Since $Date_of_Invoice is a Reference column, it contains references, not actual dates. When a reference is present, $Date_of_Invoice.Invoice_Date would be the date value (or None when the date in the referenced record is missing).

When a reference is absent, $Date_of_Invoice reference refers to a special “empty record”. In this empty record, $Date_of_Invoice.Invoice_Date will be None (the default value for a Date column), which is why @georgegevoian’s answer should work correctly.

If your goal is to check whether the reference itself is valid though (rather than the date in the referred record), you can do that by simply using it in the if condition, i.e. if $Date_of_Invoice or if not $Date_of_Invoice. This is called a “boolean context” in Python (I found a tutorial on that). In a boolean context, an empty reference is falsy. The Python bool() function can be used to convert such values to actual True / False values.

So a shorter way to express what you need is simply this:

bool($Date_of_Invoice)
2 Likes

Thanks @georgegevoian and @dmitry-grist for the clarification!

The original reference for the Date of Invoice column was actually an identifier that made the date a formatted string so that was the part I was slightly confused about.

And thanks so much for the easier solution. I totally should have looked for a bool function since all I was really checking for if it’s that or column was there or not.

2 Likes