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

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

C# code to read all customers from Dynamics AX 2012

(0) ShareShare
ReportReport
Posted on by 30

I need a c# code sample to read all customers from Dynamics Ax 2012 using aif service and display customer number, customer name alias, customer first name on console.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Lars Morgenroth Profile Picture
    265 on at
    RE: C# code to read all customers from Dynamics AX 2012

    just for further requests:

    you can achieve this by doing a service.find - operation with query criteria not equal empty.

    For example:

    CriteriaElement elem = new CriteraElement();

    elem.DataSourceName = "CustTable";

    elem.FieldName = "AccountNum";

    elem.Operator = Operator.NotEqual;

    elem.Value1 = "";

    QueryCriteria crit = new QueryCriteria();

    crit.CriteriaElement = new CriteriaElement[] { elem };

    cust = custClient.find(context, crit);

    Best regards

    Lars

  • Community Member Profile Picture
    on at
    RE: C# code to read all customers from Dynamics AX 2012

    Thanks for the code. I have used the above code for getting the list of all customers but the number of customers I can get are 30, where as the total number of customers in the database are 271.  Being a newbie, not sure what am I doing wrong.  Would be great if you look at it and let me know.

    using System;

    using System.Collections.Generic;

    using System.Linq;

    using System.Text;

    using AIFQueryCriteria.ServiceReference1;

    namespace AIFQueryCriteria

    {

       class Program

       {

           static void Main(string[] args)

           {

               ServiceReference1.CustomerServiceClient c1 = new ServiceReference1.CustomerServiceClient();

               ServiceReference1.CriteriaElement elem = new ServiceReference1.CriteriaElement();

               elem.DataSourceName = "CustTable";

               elem.FieldName = "AccountNum";

               elem.Operator = Operator.NotEqual;

               elem.Value1 = "";

               QueryCriteria crit = new QueryCriteria();

               crit.CriteriaElement = new CriteriaElement[] { elem };

               try

               {

                   AxdCustomer cust = c1.find(null, crit);

                   for (int i = 0; i < cust.CustTable.Length ; i++)

                   {

                       Console.WriteLine(cust.CustTable[i].AccountNum.ToString());

                       Console.WriteLine(cust.CustTable[i].Name.ToString());

                   }

                   Console.ReadKey();

               }

               catch (Exception ex)

               { c1.Abort(); }

               finally { c1.Close(); }

           }

       }

    }

  • Martin Dráb Profile Picture
    236,320 Most Valuable Professional on at
    RE: C# code to read all customers from Dynamics AX 2012

    Check if you're getting data from the company you expect.

    By the way, an alternative solution would be using the query service (your code is based on document services).

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Community Member Profile Picture

Community Member 4

#2
Nayyar Siddiqi Profile Picture

Nayyar Siddiqi 2

#2
NNaumenko Profile Picture

NNaumenko 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans