web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)
Unanswered

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

(0) ShareShare
ReportReport
Posted on by 50

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

*This post is locked for comments

I have the same question (0)
  • Martin Dráb Profile Picture
    237,904 Most Valuable Professional on at

    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 Profile Picture
    50 on at

    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 Profile Picture
    237,904 Most Valuable Professional on at

    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.

  • metin emre Profile Picture
    502 on at

    You saved my day, thanks!!!

  • metin emre Profile Picture
    502 on at

    I just tried like this, but crashes with CLRerror at last line, no error string returned:

    System.Type nullableType = System.Type::GetType('System.Nullable`1[System.Decimal]');

    System.Object decimalValue;

    System.Object[] paramValues = new System.Object[1]();

    decimalValue = System.Convert::ToDecimal(smmParametersTable.SNBPTTinUserPers);

    paramValues.SetValue(decimalValue, 0);

    nullableValue = System.Activator::CreateInstance(nullableType, paramValues);

    input.set_musteriId(nullableValue);

    Do you have any idea?

  • metin emre Profile Picture
    502 on at

    Please ignore my last message. It was my fault. I had to change Decimal to Int32. Thanks again, it worked...

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans