Skip to main content
Question

How to Properly Delete a Selected Row from the Database in Acumatica


Forum|alt.badge.img

        public SelectFrom<CustomTable01>.View FilterView;

        

        public PXFilter<CustomFilte> Filter;


        public virtual IEnumerable deleteLine(PXAdapter adapter)
        {

    /// Code to retrieve the PXResultset

                    foreach (var CustomTable01Row in CustomTable01Rows)
                    {
                   Method 1 --------- this.FilterView.Delete(CustomTable01Row);
                  

                   Method 2 --------- this.FilterView.Cache.Delete(CustomTable01Row);

                   Method 3 --------- this.FilterView.Delete(CustomTable01Row);

                                               this.Persist();


                   Method 4 --------- this.FilterView.Cache.Delete(CustomTable01Row);

                                               this.Actions.PressSave();
                        
                    }
    }


I created a custom screen with a filter with a results grid. When a user selects a line and presses an action button, I want to delete the selected row from the database. I retrieved the relevant row in the data access component (DAC) and attempted four different deletion methods. Methods 1 and 2 resulted in the row being deleted only from the user interface (UI). Upon screen refresh, the row reappeared. Methods 3 and 4 produced the following error. How can I fix this and delete the selected line form the database? Any detailed instructions, tips, or code snippets would be greatly appreciated. Thank you!

PX.Data.PXLockViolationException

Error: Another process has deleted the 'PTProductionPlanOrderHeaderTable' record. Your changes will be lost.

3 replies

Forum|alt.badge.img+6
  • Captain II
  • 556 replies
  • March 26, 2025

Method 1 followed up with a call to .Save (or .PressSave) should work.

But you shouldn’t need to be looping through the records. As long as your grid properties are keeping the current row in sync with the dataset you can delete the currently highlighted record.

e.g.

var curRow = FilterView.Current;

this.FilterView.Delete(curRow);

this.Actions.PressSave();

 


Forum|alt.badge.img

Hi ​@Django ,

I tried your code as follows.
            var row = FilterView.Current;
            this.FilterView.Delete(row);
            this.Actions.PressSave();

But still the following error occurs. 
 

PX.Data.PXLockViolationException

Error: Another process has deleted the 'PTProductionPlanOrderHeaderTable' record. Your changes will be lost.


Forum|alt.badge.img+6
  • Captain II
  • 556 replies
  • March 27, 2025

I feel like there’s more code than what we’re seeing. Can you show us all the code that relates to deleteLine?

First question before I go further - is there a reason you’re not using the standard [X] button that the grid view will make available to you?

Moving on, since your deletion logic is designed for a user to click on a row and then click your action button, you don’t need to use the IEnumerable version of the PXAction method. Try changing it to:

public PXAction<CustomTable01> DeleteLine;
[PXButton(CommitChanges = true)]
[PXUIField(DisplayName = "Delete Line", MapEnableRights = PXCacheRights.Select, MapViewRights = PXCacheRights.Select)]

protected virtual void deleteLine ()

{

}

This way you’re not needing to do anything with the contents of the adapter which I think might be related to your issue.

 


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings