How to pass a Nullable`1 type value to a function in AX2009

Question Status

Rob Keeris asked a question on 20 Mar 2013 10:09 AM


I am implementing a webservice.  I created the reference without problems.

In the script I run into the problem I have to pas a value to a function

  void  measurement.set_length(Nullable`1 type)

How can i pass a value to this Nullable`1 type?

In the generated source file I can see it is declared as a System.Nullable<decimal>

I tried :


But the `sign is not allowed in scripts


This gives a strange Table is out of range error..



Martin Dráb responded on 21 Mar 2013 2:13 AM

X++ doesn't support generics, so it's always a bit tricky to work with generic types in AX. Another problem may be that Nullable<T> is a structure, not a class.

I would try something like this:

System.Type nullableType = System.Type::GetType('System.Nullable`1[System.Decimal]');
System.Object decimalValue = System.Convert::ToDecimal(123);
System.Object[] paramValues = new System.Object[1]();
CLRObject nullableValue;
paramValues.SetValue(decimalValue, 0);
nullableValue = System.Activator::CreateInstance(nullableType, paramValues);
Rob Keeris responded on 21 Mar 2013 12:54 PM

Thanks for your replay.....

but is does not solve the compile-time error.

nullableValue is of type CLRObject and I can't pass it to the function.

But the hint to use System.Type::GetType('System.Nullable`1[System.Decimal]'); might be usefull. :-)

Martin Dráb responded on 21 Mar 2013 1:43 PM

It works in AX2012, but apparently not in AX2009. Sorry.

You can't use generic types in variable declaration in X++, so you'll have to change the service to accept non-generic parameters or to create a proxy client in .NET if you can't (or don't want) to change the service.