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

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

This question is not answered

Hi,

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 :

measurement.set_length(System.Nullable`1<decimal>(110));

But the `sign is not allowed in scripts

measurement.set_length(System.Nullable<decimal>(110));

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

Regards,

Rob

All Replies
  • 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);

    Martin "Goshoom" Dráb | Freelancer | Goshoom.NET Dev Blog

  • 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. :-)

  • 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.

    Martin "Goshoom" Dráb | Freelancer | Goshoom.NET Dev Blog