auto fill date field with specific date if source date field is empty.

Hello,

I am currently trying to do the following

If the expiration date field of the batch number is empty then I want to auto fill the date field on my label form with a specific date.

The user does not want the field on the label form to ever be empty. Currently this field is auto populated from the expiration date of the batch number that is selected on the label form.

Below is my current code:

This is in the INIT of my label form.

select * from inventBatch
            where inventBatch.ItemId == _sum.itemId
            && InventBatch.inventBatchId == _line.inventBatchId;
        assemblyLabel.ExpirationDate    = inventBatch.expDate;

        // conditional on Expd to populate with default date of 1/1/1900
        if(!inventBatch.expDate)
        {
            assemblyLabel.ExpirationDate = str2Date("01/01/1900",123);
        }

Hey Joe,

Could you suggest to the user that they run the update expiry dates periodic job and fill in the blank ones? They could filter for only blank ones and have the system update them so you wouldn’t have to do this logic on the report?

The value you’re trying to set is the same that AX uses for empty dates. Therefore you’re effectively making the field empty; it’s the same as assigning dateNull(). By the way, when setting hard-coded date values (usually just for test purposes, because real code uses parameters), I prefer mkDate() function. Then you don’t have to worry about date format.

Trying to run the logic during initialization of a form sounds very strange. Think again about when you want this to happen.