Skip to main content

Notifications

Supply chain | Supply Chain Management, Commerce
Answered

Retrieval of Deleted Sales Order Record

Posted on by 76
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

 
  • Verified answer
    Saurabh777 Profile Picture
    Saurabh777 76 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 76 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 76 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 76 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 Microsoft Employee 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,434 Super User 2024 Season 2 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 15,075 Most Valuable Professional on at
    Retrieval of Deleted Sales Order Record
    You can use the re insert button
  • Verified answer
    Kevin Xia Profile Picture
    Kevin Xia Microsoft Employee 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 15,075 Most Valuable Professional 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 76 on at
    Retrieval of Deleted Sales Order Record
    Hi BillurSamdancioglu 

    how to retrive , if data base log is enabled ?

    Regards
    Saurabh

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

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

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 229,275 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans