Friday, July 18, 2014

Dynamics AX - How to make a table an optional parameter in a method

I couldn't remember how to make a table value option for a method. I've done it a ton before but just couldn't recall at the time. Tried doing a few searches and didn't find anything so thought it would be a good post.

Dynamics AX can allow parameters to be optional for a given method. This is accomplished by assigning a parameter to an appropriate value at the top of the method (see below example). If there is no assignment, the parameter is required. The one rule is that all optional parameters must be after the mandatory ones. It is not allowed to have a mandatory following an optional one.

When calling the method, you can see which parameters are mandatory and which are optional as the optional values will show up with a bracket '[' in them in the intellisense.

All that being said, below is how you would accomplish making a table optional with a null value in its place. Simple assign the functions parameter to a value of 'null'.

public void processInbound(Table1 _mandoatoryTableParam, Table2 _optionalTableParam = null)


For additional information about certain data types being null values, see below:

Null Values for Data Types [AX 2012]
http://msdn.microsoft.com/en-us/library/aa846236.aspx
Type
Value treated as null
Date 1900-01-01
Enum Element with its value set to 0.
Integer 0
Real 0.0
String An empty string
Time 00:00:00
Utcdatetime Any value with its date portion as 1900-01-01 is treated as null, regardless of the time portion value. Therefore the value 1900-01-01T22:33:44 is treated as null.
NoteNote
Any utcDateTime value with its date portion as 1900-01-01 is displayed as blank by the X++ print statement. Only the value 1900-01-01T00:00:00 is displayed as blank by the Global::info method. That is the value from the DateTimeUtil::MinValue method.

No comments:

Post a Comment