Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Forums / Finance forum / To write a select stat...
Finance forum
Suggested answer

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

Posted on by 1,457
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 
  • Dineshkarlekar Profile Picture
    Dineshkarlekar 1,457 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
  • Layan Jwei Profile Picture
    Layan Jwei 6,882 Super User 2024 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?
  • Suggested answer
    Layan Jwei Profile Picture
    Layan Jwei 6,882 Super User 2024 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
     
  • Suggested answer
    Deepak Agarwal Profile Picture
    Deepak Agarwal 148 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
    }
     
     
  • Dineshkarlekar Profile Picture
    Dineshkarlekar 1,457 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);
                        }
                    }
                }
     

Helpful resources

Quick Links

Dynamics 365 Community Update – Sep 9th

Welcome to the next edition of the Community Platform Update. This is a weekly…

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,277 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,135 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans