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 get the sales orders with date range in X++ statements

(0) ShareShare
ReportReport
Posted on by 1,737

Hi,

I am Trying to get the sales orders which are created within one month

were created within the last month, and write a temp table containing the sales order number, count of lines of type ‘Item’, count of lines of type ‘Service’, count of lines of type ‘BOM’ (per ItemType enum).

how to get this?

regards,

Srinivas

*This post is locked for comments

I have the same question (0)
  • Sohaib Cheema Profile Picture
    49,438 User Group Leader on at

    Hi,

    You can get it as below SQL. Also you can create a similar query inside AX.

    Select SalesLine.SALESID,InventTable.ITEMTYPE,count(InventTable.ITEMTYPE) As CountOfItemType 
    from SalesLine
    	join InventTable 
    		on InventTable.ITEMID = SalesLine.ITEMID 
    			And InventTable.DATAAREAID = SalesLine.DATAAREAID
    where 
    	/*You can remove next line to take all sales order*/
    	SalesLine.SALESID = '000861' AND
    	SalesLine.DATAAREAID = 'USMF'  
    	/*You can remove next two lines if you dont want to filter by last month*/
    		 AND DATEPART(m, SalesLine.CREATEDDATETIME) = DATEPART(m, DATEADD(m, -1, getdate())) 
    			AND DATEPART(yyyy, SalesLine.CREATEDDATETIME) = DATEPART(yyyy, DATEADD(m, -1, getdate()))
    Group By SalesLine.SALESID,InventTable.ITEMTYPE
    

  • srinivas pamidi Profile Picture
    1,737 on at

    Hi sohaib,

    I am writing this in Job it is Throwing the Syntax error in Select SalesLine.salesId

  • Verified answer
    Sohaib Cheema Profile Picture
    49,438 User Group Leader on at

    I cannot imagine by myself what you have written in X++, but seems that you have tried to copy paste above SQL query in X++. If so, it will give you error.

    Here you go with X++ equivalent job. If you want to apply TimeZone Differences you can do so.

    SalesLine       SalesLine;
        InventTable     InventTable;    
        DateTime    varStartOfMonthDT   = DateTimeUtil::newDateTime(dateStartMth(dateMthFwd(today(),-1)), timeNow());
        DateTime    varEndOfMonthDT     = DateTimeUtil::newDateTime(dateEndMth(dateMthFwd(today(),-1)), timeNow());
        
        
        while select SALESID from SalesLine
            join ItemType, count(RecId) from InventTable 
                Group By SalesLine.SALESID,InventTable.ITEMTYPE
    		        where InventTable.ITEMID == SalesLine.ITEMID 
    			            && InventTable.DATAAREAID == SalesLine.DATAAREAID
                                    && SalesLine.createdDateTime >= varStartOfMonthDT && SalesLine.createdDateTime <= varEndOfMonthDT
                                            //&&  SalesLine.SALESID == '000861'	                
               
        {
            info(strFmt('SalesId:%1    ;   ItemType:%2  ;   CountOfItemType:%3'
                        ,SalesLine.SalesId
                        ,InventTable.ItemType
                        ,int642int(InventTable.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
Priya_K Profile Picture

Priya_K 4

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#3
Ali Zaidi Profile Picture

Ali Zaidi 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans