0

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"

splinter.cell
  • 113
  • 1
  • 7
  • How are you setting values to save? This could be part of the unexpected behavior. (Please post your code.) Also, you could try **Base.Save.Press();** instead, but since I don't know anything about your code then I don't know if it will behave differently. As for your pressing release, it is likely something like Base.Release.Press(); but again, you did not provide enough code in your post to give any better suggestions. – Brian Stevens Sep 08 '20 at 18:44
  • @BrianStevens the post has been edited – splinter.cell Sep 08 '20 at 18:59

1 Answers1

0

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.

Brian Stevens
  • 1,826
  • 1
  • 7
  • 16
  • Thank you very much, your comment is very helpful, can you help me with this problem "the update() method not work with readonly fields", and another questions please "i want to press button release on method", thank you again – splinter.cell Sep 08 '20 at 19:51
  • How is the field read-only? (Can you provide the code sample from the DAC's definition of the field?) Is the view retrieved as read only? (i.e. using PXSelectReadonly) I would need to see the code behind all that to try to help. As noted in a comment above, I suspect pressing the release button systematically is *Base.Release.Press()* but I don't know your code. Is this part of a standard Acumatica screen that you could tell me the Screen ID or Graph? – Brian Stevens Sep 08 '20 at 19:57
  • i solved the problem of saving readonly field, the problem with PDDefault(TypeCode.String, " "), when i remove it the problem solved – splinter.cell Sep 09 '20 at 07:32
  • Updated the answer to include how to Release as asked in comment above. – Brian Stevens Sep 13 '20 at 19:54