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)

How to loop through SalesSalesOrderService to get all SalesLine records in C#?

(0) ShareShare
ReportReport
Posted on by

I couldn't find any examples that loops through a document service.. i found this example for ax 2009 but got a massive headache after going through it(not sure if it's applicable to ax 2012): https://msdn.microsoft.com/en-us/library/cc652581%28v=ax.50%29.aspx (opens new window)

Here's what I have so far:

                // Create the service client proxy
                SalesOrderService.SalesOrderServiceClient c1 = new SalesOrderService.SalesOrderServiceClient();

                // Create the Call Context
                SalesOrderService.CallContext cc = new SalesOrderService.CallContext();

                // Set the partition to "MyPartition"
                cc.PartitionKey = ConfigurationManager.AppSettings["Partition"];

                // Set the company to "MyCompany"
                cc.Company = ConfigurationManager.AppSettings["Company"];

                SalesOrderService.AxdSalesOrder salesResp;

                SalesOrderService.EntityKey[] readSalesKeys = new SalesOrderService.EntityKey[1];
                readSalesKeys[0] = new SalesOrderService.EntityKey();
                readSalesKeys[0].KeyData = new SalesOrderService.KeyField[1];
                readSalesKeys[0].KeyData[0] = new SalesOrderService.KeyField();
                readSalesKeys[0].KeyData[0].Field = "SALESID";

                readSalesKeys[0].KeyData[0].Value = "000733";


How would I loop through salesResp.SalesTable[0].SalesLine[i] to get all the salesline records for this order?

Code examples would be much appreciated!

*This post is locked for comments

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

    This question is purely about C#, so you would be better off opening C# documentation or asking in a C# forum.

    Anyway, C# offers several ways how it iterate arrays. The easiest one is using foreach:

    foreach (var line in salesResp.SalesTable[0].SalesLine)
    {
        ...
    }

    You could also use the for loop, in the same way as in X++. You could also use an enumerator. But you likely want to simply use foreach.

  • Community Member Profile Picture
    on at

    Ah thanks, I didn't know it was this straightforward with AX document services.

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

    What you work with are normal .NET classes, properties, arrays etc. When you add a service reference, Visual Studio reads the web service definition and generated these so-called proxy classes for you. It doesn't actually know anything about Dynamics AX.

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