Tuesday, February 1, 2011

Set a Date Value to a Date Filed in AX 2009 with X++

I was faced with a requirement that I needed to set a date value to a custom date Filed in AX 2009 with X++, with the Purch Order Creation Date.

I knew that the following could work:

...
FormControl control;
;
control = element.design().controlName('PurchTable_OrderDate'));
control.Text = DateTimeUtil::ToStr(purchTable_ds.Object(fieldnum(PurchTable, CretationDateTime);
...

However, I wanted to create a solution that would not be so dependant on the Form object as this can bring headaches when upgrading. Therefore, I decided to do it at the data source level as follow:

purchTable_ds.object(fieldnum(PurchTable, OrderDate)).setValue(DateTimeUtil::date(purchTable.createdDateTime));

The above code is far more efficient and it needs to be set either in the Data Source (PurchTable) of the PurchTable form Init() or Active() method.

 

No comments:

Post a Comment

Thank you for your thoughts. Your comment will appear in my blog shortly after review.

Have a great day!