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 :
Finance | Project Operations, Human Resources, ...
Suggested Answer

To write a select statement in x++ for fully delivered sales order

(0) ShareShare
ReportReport
Posted on by 1,836
hi ,everyone 
 
I want to written the code in x++ select to fetch fully delivered sales order  so i can insert the selected record in table .how can i get this done , can anyone guide me on this , i have written the if condition but i am having doubt with it ,my code is below please let me know if i need to do any changes . 
thanks,
Regards,
Dinesh 
I have the same question (0)
  • Dineshkarlekar Profile Picture
    1,836 on at
    To write a select statement in x++ for fully delivered sales order
     while select forupdate salesLine
    	      join salesTable
    	      where salesLine.SalesId == salesTable.SalesId
                    &&  salesLine.SalesStatus == SalesStatus::Delivered
                    && salesTable.ISLFOC == NoYes::Yes              
                {
       			select firstonly markupTable
                    where markupTable.ModuleType == MarkupModuleType::Cust
                       && markupTable.ISLFOC == NoYes::Yes;
    
                    delete_from markupTransTmp
    					where markupTransTmp.MarkupCode == markupTable.MarkupCode
                            && markupTransTmp.TransTableId == salesLine.TableId
                            && markupTransTmp.TransRecId == salesLine.RecId;
                    costPrice = salesLine.ISLItemOnhandPhysicalCost(salesLine.ItemId, salesLine.InventTransId);
    
                    if (costPrice)
                    {
                        if(salesTable.ISLFOC == NoYes::Yes
                            && salesTable.SalesStatus == SalesStatus::Invoiced
                            && salesLine.SalesStatus == SalesStatus::Delivered )
                        {
                            salesLine.ISLUpdateCharges(salesLine, costPrice);
                        }
                        else
                        {
                            salesLine.ISLUpdateCharges(salesLine, costPrice);
                            salesLine.ISLUpdateCharges(salesLine, -costPrice);
                        }
                    }
                }
     
  • Suggested answer
    Deepak Agarwal Profile Picture
    8,598 on at
    To write a select statement in x++ for fully delivered sales order
    Hello, 
     
    Your current code seems with some custom fields in it, not quite sure about this code. However, you can find sales orders where the delivery reminder is zero which means it's fully delivered. here is a very simple code to find the records, 
     
     while select  salesLine
                where salesLine.SalesStatus == SalesStatus::Backorder
                    && salesLine.RemainSalesPhysical > 0
    {
    //your business logic
    }
     
     
  • Suggested answer
    Layan Jwei Profile Picture
    8,097 Super User 2025 Season 2 on at
    To write a select statement in x++ for fully delivered sales order
    Hi Dinesh,
     
    You can test it yourself to see if checking status=Delivered is enough or not.
     
    For example, create a sales order with two lines. One with Qty =1 and one with Qty=2.
    Confirm the order, then deliver the item with 1 Qty and and change the item2 qty to 1 in the delivery dialog.
    You'll notice that the sales order status is still open order.
     
    Click post packing slip again, to deliver the remaining qty of 1 for the 2nd item and click ok, you'll notice that the status became now delivered. which will mean that what you did is correct. You could also debug to see if it brought orders you are not interested in.

    So maybe checking SalesTable.SalesStaus = delivered is better than SalesLine to make sure the whole order is delivered(based on your requirement)
     
    We can't tell what your code does, but for example to enhance performance, you can amend few lines
     
    In the select statement for markupTrans
    Select firstOnly MarkupCode from markupTrans.....
     
    And the first select statement where you join salesTable
     
    while select.....
    join ISFLOC, SalesStatus From salesTable where....
     
    Thanks,
    Layan Jweihan
    Please mark this answer as "Verified" if it solved your issue. In order to help others who will face a similar issue in the future
     
  • Layan Jwei Profile Picture
    8,097 Super User 2025 Season 2 on at
    To write a select statement in x++ for fully delivered sales order
    Hi Dinesh,
     
    Do you still need help in this one?
  • Dineshkarlekar Profile Picture
    1,836 on at
    To write a select statement in x++ for fully delivered sales order
    hi layan 
    thanks for reply , 
    I am still working on it, let you know .give me some time .
     
    thanks,
    Regards,
    Dinesh

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 724 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 619 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 400 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans