D365 Business Central : Check if Date Formula is Blank

A date formula is a formula, abbreviated using combination of signs, letters and numbers, to calculate date. It is generally used to calculate date, such as Due Date or the next date for recurring job. I have talked about it on previous post. Today, I would like to talk on how to check if the Date Formula is empty or blank.

Unlike text variable, a Date Formula cannot be directly checked for blank using if InputDateFormula = ” then. Doing so will result in an error, as the ‘=’ operator cannot be applied to operands of type ‘DateFormula’ and ‘Text’.

Error Operator = cannot be applied to operands of type ‘DateFormula’ and ‘Text’

There are three methods that we can do to check blank Date Formula.

Format Method

Utilising the System.Format() method, we can convert the Date Formula into text and check for blankness.

procedure CheckBlankDateFormulaUsingFormat(InputDateFormula: DateFormula)
begin
    if Format(InputDateFormula) = '' then
        Error('Date Formula cannot be blank');
end;

Variable Method

Create a local Date Formula variable without assigning any value and use it for comparison. By comparing the input Date Formula with an uninitialised variable, we can determine if the input is blank.

procedure CheckBlankDateFormulaUsingVariable(InputDateFormula: DateFormula)
var
    BlankDateFormula: DateFormula;
begin
    if InputDateFormula = BlankDateFormula then
        Error('Date Formula cannot be blank');
end;

TestField Method

This method is only applicable to table fields. By making use of TestField, we can perform a blank check on the table field.

procedure CheckBlankDateFormulaUsingTestField()
var
    Item: Record Item;
begin
    Item.TestField("Lead Time Calculation");
end;
Error Lead Time Calculation must have a value.

That’s it. It’s quite straightforward. Hope you learn something new.

thatnavguy

Experienced NZ-based NAV Developer and Consultant with 15+ years of experience leading multiple IT projects, performing business analyst, developing, implementing, and upgrading Dynamics NAV and Business Central. Passionate to deliver solution that focuses on user-friendly interface while keeping high standard of compliance with the needs.

You may also like...

Leave a Reply

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