在acumatica中动态更改方法中的数据时,单击“保存和释放”按钮?

问题描述

我有一个名为PayEFTPOS的按钮, See Image Here

单击此按钮时将调用此方法

[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();`

}

在这种方法中,“说明和付款金额”字段中的数据将动态更改
然后点击保存按钮以动态保存数据 但问题是“这些字段中的数据仅在ui中已更改,但刷新后未更改”

解决方法

当我第一次开始时,这让我感到非常难受。提供的代码实际上并没有更新视图后面的缓存。结果是缓存不是 dirty ,因此无法识别为需要保存。取而代之的是,更新缓存记录的您的副本,这与实际缓存本身有很大不同。有几种方法可以做到这一点,但是到目前为止,与您的代码保持一致,您应该能够简单地执行如下所示的更新。

[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)
}

请注意,当您更新视图(.Update方法)时,它将触发相关基础图和图扩展中的所有事件处理程序。如果您打算继续使用此记录,则应使用语法 documents = Base.Document.Update(documents); ,以便同时更新记录(文档)的副本。否则,您可能会添加更多更改,再次更新视图,并且会丢失事件处理程序执行的更改。

作为旁注,由于暗示了 this ,因此不必指定 this.Base 。您只需声明 Base 即可保存一些击键。使用 this Base 可以帮助我跟踪是否要在当前图形/扩展名或基础图形中调用代码,以及 this.Base 让我花点时间思考一下我要调用的代码在哪里。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...