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 :
Finance | Project Operations, Human Resources, ...
Answered

Managing Data With List

(0) ShareShare
ReportReport
Posted on by 114

Hello everyone, 

I'm trying to get data from a web service. There is a method name is "getCurrencyID" returning data as lista according to the web services document. I get the data with C# but i coudn't compile my code on AX. I had similar issue for another method on same web service. I fixed that problem with this solution link

This is what web services document says;

GetValueListResponse
{
    "Status" : string, // Success , Error
    "StatusMessage" : string,
    "Properties" : List
}

Property
{
    "Key" : string // ID
    "Value" : string // Name
}

This is my C# code;

string _currencyID = client.GetCurrencyId(token, "USD").Properties[0].Key;

I tried to compile it on AX like this;

List currencyIDList = new List(Types::String);


getValueListResponse = axClient.GetCurrencyId(token,"USD");
currencyIDList = getValueListResponse.get_Properties(0).Key;

When i tried to compile it I'm getting this error; "Argument '0' is incompatible with the required type."

How can i solve this? 

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

    There are several bugs. get_Properties(0) isn't an equivalent of Properties[0. You need to use get_Key() to access the Key property. And according to your C# code, its type is string, while you're trying to assing it to a variable of List type.

    I'll assume that the type of Properties is an array of classes.

    You need to get the array by calling get_Properties(), access its element with index 0 and then get a value from its Key property. For example:

    SomeNamespace.SomeType[] properties = getValueListResponse.get_Properties();
    SomeNamespace.SomeType firstProperty = properties.GetValue(0);
    str currencyId = firstProperty.get_Key();

    By the way, if you need to put all keys to a list, don't both with indexes at all. Use an enumerator instead.

  • Emre Karakus Profile Picture
    114 on at

    Hello Martin,

    Thank you for your quick response. I tried how you explained but i get this error "Index was outside the bounds of the array." for this step "SomeNamespace.SomeType firstProperty = properties.GetValue(0);" from web service.

  • Martin Dráb Profile Picture
    237,959 Most Valuable Professional on at

    It seems that your array doesn't contain any elements. If you try access an element that doesn't exist, you'll get an error.

    By the way, do you know that you can use the debugger to see contents of your variables?

  • Emre Karakus Profile Picture
    114 on at

    Variables running with this web service do not display contents.

  • Martin Dráb Profile Picture
    237,959 Most Valuable Professional on at

    I guess that you're running your code in X++ and using the MorphX debugger. Switch to CIL and Visual Studio and see the difference. When I used to work with AX 2012, I sometimes switched to CIL just because of debugging, especially when dealing with .NET types (like in this case) and for conditional breakpoints.

    By the way, is your problem with "Index was outside the bounds of the array" resolved?

  • Emre Karakus Profile Picture
    114 on at

    Thank you for your advice.

    No, unfortunately i couldn't solve that problem.

  • Verified answer
    Martin Dráb Profile Picture
    237,959 Most Valuable Professional on at

    If you agree with assumption about the cause of the problem, i.e. that the array is empty, you obviously must stop trying to access the first element if the array contains none.

    I suggest two options:

    1. If you're only interested in the first element, check if get_Lenght() is higher than zero.
    2. If you want to get all elements, use an enumerator. Like this:

    System.Collections.IEnumerator enumerator = properties.GetEnumerator();
    while (enumerator.MoveNext())
    {
    	property = enumerator.get_Current();
    }

    If you still have a problem with it and you want our help, don't forget explain the problem.

  • Emre Karakus Profile Picture
    114 on at

    You are right Martin. The first element if the array contains none. But i didn't understand. How it's working with C#? What is my mistake?

  • Martin Dráb Profile Picture
    237,959 Most Valuable Professional on at

    It seems that there was at least one element when you run your C# code. Again, the debugger is there to help you - you can see what data you've received.

    Your mistake is trying to access elements of the array without checking if there are any. My previous reply mentions two ways how you can solve this problem.

  • Emre Karakus Profile Picture
    114 on at

    İ followed your ways. In this way, I saw that the first element if the array contains none. I don't know how to switch to CIL and Visual Studio for see the difference but i will make research. You did your best. Thank you for everything.

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 592 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 478 Super User 2025 Season 2

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 305 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans