1

I have a table with two fields: FromDate and ToDate. I want to make sure that the ToDate value is always later than the FromDate value.

To do this, I want to set the ToDate value to the FromDate value + 1. To do this I have implemented the following code in the validateField method of the table:

boolean ret;

ret = super(_fieldIdToCheck);

if (ret)
{
    switch (_fieldIdToCheck)
    {
        case fieldNum(MyTable, FromDate):
            this.ToDate = this.FromDate + 1;
    }
}

return ret;

This implementation works well, but the value of ToDate can be changed to a value before FromDate. How can this be prevented?

dogsgod
  • 6,267
  • 6
  • 25
  • 53
ulisses
  • 1,549
  • 3
  • 37
  • 85
  • Your question is a bit unclear. Are you just trying to validate the ToDate field, or are you attempting something else? – Spencer Kershaw Apr 10 '15 at 19:06
  • You shouldn't modify values in the `validateField` method, but instead use the `modified` method or another relevant one. – Alex Kwitny Apr 10 '15 at 19:11
  • Spencer Kershaw you have a reason, thanks for your help, I I do not want to confirm the ToDate field, but I want to set up this field in relation to FromDate. For example: If in my FormDate field I insert date : 13/04/2015 -> in ToDate field automatically to show only calendar part subsequent to the date entered in FromDate field.(start 13/04/2016). If it's is possbile, thanks! – ulisses Apr 13 '15 at 07:22

1 Answers1

0

As Alex said, use the table method modifiedField to do field dependant modifications.

If you change the field by code remember to call the method yourself.

Maybe you should make the assignment conditional to avoid overwriting user entered date. This will also work well if ToDate is initially null.

public void modifiedField(FieldId _fieldId)
{
    super(_fieldId);
    switch(_fieldId)
    {
        case fieldNum(MyTable, FromDate): 
        case fieldNum(MyTable, ToDate): 
            if (this.ToDate < this.FromDate) // mostly first time
                this.ToDate = this.FromDate + 1;
            break; // don't forget the break
    }
}
Jan B. Kjeldsen
  • 17,817
  • 5
  • 32
  • 50
  • Jan B. Kjeldsen thanks! your answer will be in acceptance, many graces. I have only last question, It's possible in Dynamica Ax to show in Todate field his calendar only the part subsequent to the date entered in from dates. Look like in the sites of booking flights form. Thanks for you time, greetings! – ulisses Apr 13 '15 at 07:16
  • No. The standard date lookup form does not accept a date interval. But it would be possible to make one. Not an easy task though. – Jan B. Kjeldsen Apr 13 '15 at 07:29
  • Thanks for your help Jan B. Kjeldsen! – ulisses Apr 13 '15 at 12:18