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)

Display Method With Count

(0) ShareShare
ReportReport
Posted on by 80

Hi,

I'm fairly new to AX and trying to create a display method to count the number of detail lines per order.

So far my display method counts the lines, but puts the same counted value (the last counted value) next to all the orders.

Here is my current method :

display int64 counter()
{   OrderDetail orderDetail;
    OrderHeader orderHeader;
    int64 x;
         while select count(RecId)
        from OrderDetail
             join OrderHeader
             group by OrderHeader.OrderId
                           where OrderHeader.OrderId == OrderDetail.OrderId
    {
        x= Orderdetail.RecId;
    }
      return x;
}

Thank you in advance for the help.

*This post is locked for comments

I have the same question (0)
  • Bilal Issa Profile Picture
    4,370 on at

    Hi ,

    if you have this method on the datasource you need to set the parameter of the datasource record like the follwoing

    display int64 counter(OrderDetail _OrderDetail)

    {  

       .......

    }

  • Adrian85 Profile Picture
    80 on at

    Hi Bilal,

    The method is on the OrderHeader Table.

    If I set the parameters i get errors whenopening my form "called with invalid parameters"

    Thanks,

  • Verified answer
    Bilal Issa Profile Picture
    4,370 on at

    Hi,

    if you have this method on the OrderHeader , then you need to use this instead in the where condition, like the following :

    display int64 counter()

    {  

      OrderDetail orderDetail;

       OrderHeader orderHeader;

       int64 x;

            while select count(RecId)

           from OrderDetail

                join OrderHeader

                group by OrderHeader.OrderId

                              where OrderHeader.OrderId == this.OrderId

       {

           x= Orderdetail.RecId;

       }

         return x;

    }

  • Adrian85 Profile Picture
    80 on at

    Thank you very much Bilal, it's working 100%

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

    Nevertheless the code is quite suspicious - there doesn't seem to be any need for the loop and OrderDetail and OrderHeader are not joined by any fields.

    I assume that you wanted to write something like this:

    display int64 counter()
    {  
        OrderDetail orderDetail;
    
        select count(RecId)	from orderDetail
    	where orderDetail.OrderId == this.OrderId;
    
         return orderDetail.RecID;
    }

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