Skip to main content
Solved

Press Save automatically when updating a field

  • August 27, 2021
  • 3 replies
  • 1358 views

SadokHanini
Freshman II

Hello Guys,

 

I wanna simulate the press action on save when updating a field 
i m using this code: 

protected void Choixfournisseurline_Selected_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
{

      var row = (Choixfournisseurline)e.Row;
      PXCache cache2 = this.Caches[typeof(Choixfournisseurline)];
      cache2.Persist(row , PXDBOperation.Update);
      this.Save.Press();
      this.Save.SetPressed(true);
      cache.Graph.Actions.PressSave();
      //cache2.Graph.Actions.PressSave();

}

but it’s not working! 

 

Thanks.

Best answer by Naveen Boga

Hi @SadokHanini  I also got the same requirement and I reachedout to Acumatica support team on this and below is the response.

Acumatica Support Team Response

First and foremost, saving is not allowed from event handlers.  Acuminator will report it as PX1043 - Changes cannot be saved to the database from event handlers.  If saving is absolutely must for each row, one way will be to do this using javascript. See example below.  Either way, one will still incur ERP transaction with each save. 

 

 <script type="text/javascript">

                        function saveThisRow(s, e) {
                            var ds = px_all["ctl00_phDS_ds"];
                            if (ds != null) {
                                var fld = e.cell.column.dataField;
                                if (fld == "FieldName") ds.executeCallback("Save");
                            }
                        }
                    </script>

                    <px:PXGrid ID="gridPackageDetailSplit" runat="server" SyncPosition="True" SkinID="DetailsInTab" Caption="Contents of Selected Package" Width="100%">
                        <Mode InitNewRow="True"/>
                        <AutoSize Enabled="True"/>
                        <ClientEvents AfterCellUpdate="saveThisRow" />
                        <Levels>

 

Just thought of sharing it here. Hope this helps to you!

View original
Did this topic help you find an answer to your question?

3 replies

Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • 3412 replies
  • August 27, 2021

Hi @SadokHanini  In my opinion, It is NOT recommended to invoke the SAVE action inside the FieldUpdated event, due to caches may not persist properly and always β€œSAVE” action will be enabled state.

And also, it is better to hear the feedback from the Acumatica support team on this.


Hi @SadokHanini 

 

To invoke save: Base.Actions.PressSave();

It is not advised to do it on the updated fields and remember each save contributes to the ERP transactions count on the license model.

 


Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • 3412 replies
  • Answer
  • October 14, 2021

Hi @SadokHanini  I also got the same requirement and I reachedout to Acumatica support team on this and below is the response.

Acumatica Support Team Response

First and foremost, saving is not allowed from event handlers.  Acuminator will report it as PX1043 - Changes cannot be saved to the database from event handlers.  If saving is absolutely must for each row, one way will be to do this using javascript. See example below.  Either way, one will still incur ERP transaction with each save. 

 

 <script type="text/javascript">

                        function saveThisRow(s, e) {
                            var ds = px_all["ctl00_phDS_ds"];
                            if (ds != null) {
                                var fld = e.cell.column.dataField;
                                if (fld == "FieldName") ds.executeCallback("Save");
                            }
                        }
                    </script>

                    <px:PXGrid ID="gridPackageDetailSplit" runat="server" SyncPosition="True" SkinID="DetailsInTab" Caption="Contents of Selected Package" Width="100%">
                        <Mode InitNewRow="True"/>
                        <AutoSize Enabled="True"/>
                        <ClientEvents AfterCellUpdate="saveThisRow" />
                        <Levels>

 

Just thought of sharing it here. Hope this helps to you!


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