Click On Save and Release Buttons when change data in method dynamically in acumatica?

546 views Asked by At

I have a button called PayEFTPOS, See Image Here

when click on this button will invoke this method

[PXButton(CommitChanges = true)]
[PXUIField(DisplayName = "Pay EFTPOS")]
protected void customAddView()
{
   var documents = this.Base.Document.Current;
   documents.DocDesc = "Value 1";
   documents.ExtRefNbr = "Value 2";
   this.Base.Actions.PressSave();`

}

in this method the data of fields "Description and payment amount" will change dynamically
then will click on save button to save the data dynamically but the problem is "the data in these fields changed in ui only but after refresh not changed"

1

There are 1 answers

4
Brian Stevens On BEST ANSWER

This bit me a lot when I first started. The code provided does not actually update the cache behind the view. The result is that the cache is not dirty so it is not recognized as needing to be saved. Instead, your copy of the cached record is updated, which is very different from the actual cache itself. There are several ways to do this, but in keeping with your code so far, you should be able to simply do an Update as shown below.

[PXButton(CommitChanges = true)]
[PXUIField(DisplayName = "Pay EFTPOS")]
protected void customAddView()
{
   var documents = Base.Document.Current;  // This saves the cache to a temporary object
   documents.DocDesc = "Value 1";
   documents.ExtRefNbr = "Value 2";
   Base.Document.Update(documents);  // This updates the actual cache with your changes and causes event handlers to fire
   Base.Actions.PressSave();
   Base.release.Press();  // Press the release button in the base graph (as asked in comment)
}

Note that when you update the view (the .Update method) then it will fire any event handlers in the related base graph and graph extension(s). If you plan to continue working with this record, you should use the syntax documents = Base.Document.Update(documents); so that your copy of the record (documents) is updated as well. Otherwise, you could add more changes, update the view again, and run into trouble having lost changes performed by event handlers.

As a side note, it is not necessary to specify this.Base as this is implied. You can simply state Base to save some keystrokes. Using this vs. Base helps me keep track of if I am trying to call code in the current graph/extension or in the Base graph, and this.Base takes me a moment to mentally process as to which place the code resides that I am calling.