How to use Remove(), Removeif() to Delete Records in Header Table & Lines Table

When we delete a record in the Header Table, the related lines in the Lines Table need to be
deleted as well.

High level resolution steps

    I have added a button and labeled it as Delete. It will act as a global delete for the selected records
    in the Header Table and its corresponding lines in the Lines Table.

    Detailed resolution steps

    Step 1: Add a button control. In the OnSelect property of that button, write the following code:

    Here I’ve Inserted a Form In that Form i will get Selected Data
    From(datatable_PRHeaderTableOffline), Here in that PRLinesTableOffline i have a Lookup Column
    related to PRHeadertableOffline.

    So, When I click on Delete Button, First It will Delete the Lines of Selected Data from in the
    PRLinesTableOffline and then in PRHeadertableOffline Based on Sele2cted PRHeader.

      
      RemoveIf(
          PRLineTableOfflines, 
          PRHeaderTableOffline.PRHeaderID = 
      DataTable_PRheader.Selected.PRHeaderID
      );
      // Delete the PR Header record
      Remove(
          PRHeaderTableOfflines, 
          DataTable_PRheader.Selected
      );
          

      Explanation of Code:

      • RemoveIf() Function: Remove Related Line Records
      RemoveIf(
      PRLineTableOffline,
      PRHeaderTableOffline.PRHeaderID =
      DataTable_PRheader.Selected.PRHeaderID
      );

      This part deletes all the line items (e.g., purchase request lines) that are linked to the selected header
      record (e.g., purchase request header).

      • Remove () Function: Remove the Selected Header Record

      Remove( PRHeaderTableOffline, DataTable_PRheader.Selected );

      After deleting the related line items, this part deletes the header record itself (e.g., purchase request
      header).

      Output

      When you select a header record (like a purchase request), clicking the Delete button will:

      1. First, remove all related line items from the Lines Table.
      2. Then, delete the header record from the Header Table.

      We have a Header Table Record and its Related Lines now when we Delete the Header Record It Will
      Delete Its Related Lines and Header Record