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)

AX 2012 X++ select statement to loop through multiple records - translate to C#

(0) ShareShare
ReportReport
Posted on by 935

What is the best way to translate an AX 2012 X++ select statement to loop through multiple records like the X++ code below into an AX C# project using the C# language?

I am looking to write as little as possible in X++ and right now trying to find out the best way to select a set of records and loop through them in C#.

Is there something comparable I can use in C# in place of the code below?

Is it necessary to create an AX helper class/method to perform the AX select statement and then return that table object back to my C# class/method? If so what container object is best to return multiple records??

Thank you for your help

// Example X++ code

while select ledgerTrans

    order by accountNum, transDate

    where ledgerTrans.accountNum >= '11100'    

        && ledgerTrans.accountNum <= '11190'    

        && ledgerTrans.transDate >= 01\07\1999

        && ledgerTrans.transDate <= 30\06\2000

{

    // Do whatever is needed.

}

*This post is locked for comments

I have the same question (0)
  • 640579632b5c4e6780a624c4771b6f93 Profile Picture
    4,730 on at

                    ax.Logon(null, null, null,  null);

     

                    AxaptaRecord custtable = ax.CreateAxaptaRecord("custtable");

                  

                    ax.ExecuteStmt(@"select %1.Description FROM %1", custtable );

                    while (custtable .Next())

                    {

                        Console.WriteLine(custtable.get_Field("Description"));

                    }

  • Sylvryd Profile Picture
    935 on at

    Thanks for the quick response.

    I have run into some cases where running the code in a AX C# project creates an exception.

    blogs.msdn.com/.../net-interop-to-x-when-x-runs-as-cil.aspx

    According to the article above the X++ method ExecuteStmt runs as CIL, a Microsoft.Dynamics.AX.ManagedInterop.OperationNotSupportedInILException exception is thrown when not running as CIL

    Have you run into that before?

  • Verified answer
    venkatesh vadlamani Profile Picture
    3,180 on at

    you have Query services and MetaData services.

    Create a query in AOT and through query service consumption in  .net you can get all the resultset returned by the query.

    This comes with paging and also operation is faster as result set is held in .Net Inmemory tables.

  • Sylvryd Profile Picture
    935 on at

    Thank you for your suggestion. I see there is enough detail in the link below to give me what i need using the Query Service.

    msdn.microsoft.com/.../gg847959.aspx

    Thanks

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