Skip to main content
Supply Chain Management forum
Answered

Retrieval of Deleted Sales Order Record

editSubscribe (0) ShareShare
ReportReport
Posted on by 51
Hi All ,

Our customer is having a record of deleted Sales order, They are looking for a way to retrieve it , back to Sales order form ( Sales Table) , I told them currently there is no way to do the  same , I also told them they can view in Voided Sales Order form report . but they need details related to Sales Order header , and want it back in Sales Order form 

please let me know and revert on this query , if you have any suggestions , TIA

Regards
Saurabh Khatri

 
Categories:
  • Verified answer
    Saurabh777 Profile Picture
    Saurabh777 51 on at
    Retrieval of Deleted Sales Order Record
    Hi all 

    We have raised a Microsoft Support Ticket and conclusion  Here is in AR  parameters we have enabled Mark order as voided to yes , so when user deletes the Sales Order it stores in voided sales order table from there we can use customised script to retrieve it back to Sales Order table , In our case the Sales order status is Invoiced 

    Customised code given by MS is below it can be used to  retrieve sales order if the AR parameter 
    Mark order as voided is marked to yes  only .

    public static void main(Args _args)
    {
    SalesTableDelete salesTableDelete;
    SalesLineDelete salesLineDelete;
    SalesTable salesTable;
    SalesLine salesLine;
    Map Map = new Map(Types::String, Types::Record);
    SalesTableDelete = SalesTableDelete::find('Sales Order number', true);
    ttsbegin;
    switch (salesTableDelete.Cancelled)
    {
    case Voided::Voided:
    {
    salesTable = conpeek(salesTableDelete.SalesTable, 1);
    salesTable.doInsert();
    while select forupdate salesLineDelete
    where salesLineDelete.SalesId == salesTableDelete.SalesId
    {
    salesLine = conpeek(salesLineDelete.SalesLine, 1);
    salesLine.doInsert();

    /*we have commented this because we were getting inventory transactions already exist error
    /* InventTransOriginSalesLine originSalesLine;
    {
    select * from originSalesLine where
    originSalesLine.InventTransOrigin == InventTransOrigin::findByInventTransId(salesLine.InventTransId).RecId;
    if (!originSalesLine.InventTransOrigin)
    {
    originSalesLine.InventTransOrigin = InventTransOrigin::findByInventTransId(salesLine.InventTransId).RecId;
    originSalesLine.SalesLineDataAreaId = salesLine.DataAreaId;
    originSalesLine.SalesLineInventTransId = salesLine.InventTransId;
    originSalesLine.doInsert();
    }
    }*/
    salesLineDelete.delete();
    }
    salesTableDelete.delete();
    }
    break;
    case Voided::linesVoided :
    while select forupdate salesLineDelete where salesLineDelete.SalesId == salesTableDelete.SalesId
    {
    salesLine = conpeek(salesLineDelete.SalesLine, 1);
    salesLine.insert();
    Map.insert(salesLine.RecId, salesLine);
    salesLineDelete.delete();
    }
    salesTableDelete.delete();
    break;
    }
    ttscommit;

    }
     
     

    public static void main(Args _args)
    ```
    - `public static void main(Args _args)`: This line defines the entry point of the program. It's a static method called `main` which takes an `Args` object as a parameter. In X++, `Args` is a base class for arguments that can be passed to a method.

    SalesTableDelete    salesTableDelete;        
    SalesLineDelete     salesLineDelete;        
    SalesTable          salesTable;       
    SalesLine           salesLine;       
    Map                 Map = new Map(Types::String, Types::Record);
    ```
    - These lines declare variables:
      - `SalesTableDelete`, `SalesLineDelete`, `SalesTable`, and `SalesLine` are objects representing different tables and entities within Dynamics 365 Finance and Operations.
      - `Map` is a collection used to store key-value pairs. Here, it's initialized with a key type of `String` and a value type of `Record`.

    SalesTableDelete = SalesTableDelete::find('SO00026380', true);
    ```
    - `SalesTableDelete = SalesTableDelete::find('SO00026380', true);`: This line finds a sales order with the ID 'SO00026380' and assigns it to the `SalesTableDelete` variable. The second parameter `true` specifies that the system should throw an error if the record is not found.

    ttsbegin;
    ```
    - `ttsbegin;`: This line begins a transaction. `tts` stands for "table transaction." It ensures that the subsequent database operations are treated as a single transaction, maintaining data integrity.
    ```csharp
    switch (salesTableDelete.Cancelled)
    ```
    - `switch (salesTableDelete.Cancelled)`: This line initiates a switch statement based on the value of the `Cancelled` field of the `SalesTableDelete` object.
    ```csharp
    case Voided::Voided:
    ```
    - `case Voided::Voided:`: This line checks if the `Cancelled` field is set to `Voided::Voided`. If it is, the code block following this case statement will be executed.
    ```csharp
    salesTable  = conpeek(salesTableDelete.SalesTable, 1);
    ```
    - `salesTable  = conpeek(salesTableDelete.SalesTable, 1);`: This line retrieves the first record from the `SalesTable` field of the `salesTableDelete` object and assigns it to the `salesTable` variable. `conpeek` is used to access the contents of a container.
    The explanation continues in the next message due to space limitations.
     
  • Saurabh777 Profile Picture
    Saurabh777 51 on at
    Retrieval of Deleted Sales Order Record
    Hi all ,

    i checked the data base logging , how to setup and get data , but my requirement from customer is the sales order record should get back to sales order from in data base logging we can just see who deleted, updated and changed the record but there is no button where we can get invoiced sales order back to Sales table.

    Regards
    Saurabh Khatri
  • Saurabh777 Profile Picture
    Saurabh777 51 on at
    Retrieval of Deleted Sales Order Record
    hi Kevin Xia

    Thankyou for suggestions next step is to raise MS ticket as data base log is not enabled in d365fo

    Regards
    Saurabh Khatri
  • Saurabh777 Profile Picture
    Saurabh777 51 on at
    Retrieval of Deleted Sales Order Record
    Hi all 

    thankyou for your responses , currently data base log for sales table is not enabled  in our business environments . so  i we will be raising a MS ticket once i get approval and will keep you posted once we close the issue after discussing with MS support ,Thanks

    Regards
    Saurabh Khatri
  • Kevin Xia Profile Picture
    Kevin Xia on at
    Retrieval of Deleted Sales Order Record
    Hi,
    Has your problem been solved? If so, you can mark the thread as verified so that other users of the forum can view the post.
    Best regards,
    Kevin
  • Verified answer
    Navneeth Nagrajan Profile Picture
    Navneeth Nagrajan 1,164 on at
    Retrieval of Deleted Sales Order Record
    Hi,

    If you have database logging enabled by default, then you should be able to see it under the System Administration section -> Setup -> Database log. If its hard to retrieve this data then you can alternatively raise a request in LCS and request Microsoft to retrieve the record details. The list for Database logging is a bit cluttered and it will be hard to find out the entire details of the sales order so recommend that you raise a request with MS and get a copy of that data for reference purposes and restore the same data into a lower environment and create the sales order manually/through integration (based on the scenario). 
     
     
  • Verified answer
    BillurSamdancioglu Profile Picture
    BillurSamdancioglu 13,084 Super User on at
    Retrieval of Deleted Sales Order Record
    You can use the re insert button
  • Verified answer
    Kevin Xia Profile Picture
    Kevin Xia on at
    Retrieval of Deleted Sales Order Record
    Hi,
    You can refer to this blog: dynamics-tips.com, in this article I will show you how to set up database logging and then give you a click by click walkthrough and demonstrate the functionality. We will also look at how you maintain this feature. 
    Best regards. You can focus on the "Type of change" field in the form.

    Kevin
  • Verified answer
    BillurSamdancioglu Profile Picture
    BillurSamdancioglu 13,084 Super User on at
    Retrieval of Deleted Sales Order Record
    On database log form, there is a button to retrieve data for the type of delete.
  • Saurabh777 Profile Picture
    Saurabh777 51 on at
    Retrieval of Deleted Sales Order Record
    Hi BillurSamdancioglu 

    how to retrive , if data base log is enabled ?

    Regards
    Saurabh

Helpful resources

Quick Links

What Motivates a Super User?

We know many of you visit the Dynamics 365 Community and Power Platform…

Demystifying Copilot with Georg Glantschnig…

Industry experts answer burning questions directly from our amazing Community…

Setting Up Knowledge Sources for Copilot…

Look at how configuring a comprehensive knowledge base is crucial…

Leaderboard

#1
Andre Arnaud de Calavon Profile Picture

Andre Arnaud de Cal... 283,045 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 222,570 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,138

Product updates

Dynamics 365 release plans