Solved

Save only selected rows in grid

  • 10 October 2023
  • 8 replies
  • 150 views

Userlevel 3
Badge

Hi Team,

Need to know how to save only selected rows records only. Can someone help me out?

 

Thanks

 

icon

Best answer by jinin 16 October 2023, 18:11

View original

8 replies

Userlevel 4
Badge

Hi,

 

I would suggest,

Override the RowPersisting event for the lines, in there check to see if the Select box is ticked, if so call the base row persisting method, if not do nothing.

I’m not 100% sure if the do nothing piece will be sufficient to stop the save on the unselected lines.  You might need to do something to remove the lines you don’t want to save from the cache (within the row persisting event) or raise some kind of event.

 

Maybe have a go and share you code if your not getting the outcome you want?

 

JOhn

 

 

Userlevel 7
Badge +11

Hi @bhagyat25 ,

As @JWS539  suggested use the Row persisting event or override the persist method and implement the logic. Loop all the records and if the select checkbox is marked as false, delete the line items from the grid.

 protected virtual void PrimaryDAC_RowPersisting(PXCache sender, PXRowSelectedEventArgs e, PXRowSelected baseEvent)
        {
            if (e.Row == null) return;

            foreach (DACName obj in ViewName.Select())
            {
                if(obj.Selected==false)
                {
                    View.Delete(obj);
                }
            }
        }
 

Userlevel 3
Badge

Hi @bhagyat25 ,

As @JWS539  suggested use the Row persisting event or override the persist method and implement the logic. Loop all the records and if the select checkbox is marked as false, delete the line items from the grid.

 protected virtual void PrimaryDAC_RowPersisting(PXCache sender, PXRowSelectedEventArgs e, PXRowSelected baseEvent)
        {
            if (e.Row == null) return;

            foreach (DACName obj in ViewName.Select())
            {
                if(obj.Selected==false)
                {
                    View.Delete(obj);
                }
            }
        }
 

Hi @jinin ,

I tried your code but it is not working as I expected. record is moving to the deleted cache from the updated cache list. But still it is updating. 

Userlevel 7
Badge +11

Hi @bhagyat25 ,

Did u try the same logic with Persist override?

 [PXOverride]
 public void Persist(Action del)
 {
     foreach (DACName obj in ViewName.Select())
        {
                if(obj.Selected==false)
                {
                    View.Delete(obj);
                }
            }

            del();
        }

Userlevel 3
Badge

Hi @bhagyat25 ,

Did u try the same logic with Persist override?

 [PXOverride]
 public void Persist(Action del)
 {
     foreach (DACName obj in ViewName.Select())
        {
                if(obj.Selected==false)
                {
                    View.Delete(obj);
                }
            }

            del();
        }

Hi @jinin,

How to call this method? Can you please tell me how to call this method in the graph?

Userlevel 7
Badge +11

Hi @bhagyat25 ,

Did u try the same logic with Persist override?

 [PXOverride]
 public void Persist(Action del)
 {
     foreach (DACName obj in ViewName.Select())
        {
                if(obj.Selected==false)
                {
                    View.Delete(obj);
                }
            }

            del();
        }

Hi @jinin,

How to call this method? Can you please tell me how to call this method in the graph?

Hi @bhagyat25 ,

This is the Save action override method. you can use the same code. and write logic inside..

Userlevel 3
Badge

Hi @bhagyat25 ,

Did u try the same logic with Persist override?

 [PXOverride]
 public void Persist(Action del)
 {
     foreach (DACName obj in ViewName.Select())
        {
                if(obj.Selected==false)
                {
                    View.Delete(obj);
                }
            }

            del();
        }

Hi @jinin,

How to call this method? Can you please tell me how to call this method in the graph?

Hi @bhagyat25 ,

This is the Save action override method. you can use the same code. and write logic inside..

Hi @jinin, I tried it too. But that method is not calling. In order to confirm that I put a break point in my visual studio project and put a break point and attached the running instance, But that method is not calling.

        [PXOverride]
        public void PersistMethod(Action del, PXCache sender, PXRowSelectedEventArgs e, PXRowSelected baseEvent)
        {
            foreach (HMRCVendorRegisterDetail obj in VendorRegisterDetail.Select())
            {
                if (obj.UsrSelect == false)
                {
                    VendorRegisterDetail.Delete(obj);
                }
            }

            del();
        }

Userlevel 7
Badge +11

Hi @bhagyat25 ,

Did u try the same logic with Persist override?

 [PXOverride]
 public void Persist(Action del)
 {
     foreach (DACName obj in ViewName.Select())
        {
                if(obj.Selected==false)
                {
                    View.Delete(obj);
                }
            }

            del();
        }

Hi @jinin,

How to call this method? Can you please tell me how to call this method in the graph?

Hi @bhagyat25 ,

This is the Save action override method. you can use the same code. and write logic inside..

Hi @jinin, I tried it too. But that method is not calling. In order to confirm that I put a break point in my visual studio project and put a break point and attached the running instance, But that method is not calling.

        [PXOverride]
        public void PersistMethod(Action del, PXCache sender, PXRowSelectedEventArgs e, PXRowSelected baseEvent)
        {
            foreach (HMRCVendorRegisterDetail obj in VendorRegisterDetail.Select())
            {
                if (obj.UsrSelect == false)
                {
                    VendorRegisterDetail.Delete(obj);
                }
            }

            del();
        }

 

public void PersistMethod(Action del, PXCache sender, PXRowSelectedEventArgs e, PXRowSelected baseEvent)

This is wrong

You should use like below(Check my sample above)

public void Persist(Action del) {
 

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved