【发布时间】:2021-03-25 22:58:55
【问题描述】:
这是我完成 Acumatica 开发人员培训后的第一次开发。
我正忙于批量付款屏幕 (AP305000) 上的用户批准。这个想法是当当前用户打开批量支付时,自定义字段默认为当前用户名。我为审批者添加了 2 个自定义字段。有 2 个审批人。
public class CABatchExt : PXCacheExtension<PX.Objects.CA.CABatch>
{
#region UsrApprover1
[PXDBString(255, IsFixed = true)]
[PXUIField(DisplayName = "Approver 1")]
[PXDefault(false, PersistingCheck = PXPersistingCheck.Nothing)]
public virtual string UsrApprover1 { get; set; }
public abstract class usrApprover1 : PX.Data.BQL.BqlString.Field<usrApprover1> { }
#endregion
#region UsrApprover2
[PXDBString(255, IsFixed = true)]
[PXUIField(DisplayName = "Approver 2")]
[PXDefault(false, PersistingCheck = PXPersistingCheck.Nothing)]
public virtual string UsrApprover2 { get; set; }
public abstract class usrApprover2 : PX.Data.BQL.BqlString.Field<usrApprover2> { }
#endregion
}
自定义字段从未启用,我在 RowSelected 事件中填充它们:
protected void _(Events.RowSelected<CABatch> e)
{
var row = (CABatch)e.Row;
CABatchExt batchExt = PXCache<CABatch>.GetExtension<CABatchExt>(row);
// disable approver 1 and 2
PXUIFieldAttribute.SetEnabled<CABatchExt.usrApprover1>(e.Cache, e.Row, false);
PXUIFieldAttribute.SetEnabled<CABatchExt.usrApprover2>(e.Cache, e.Row, false);
// get the current logged in user
Users currentUser = PXSelect<Users, Where<Users.username,
Equal<Current<AccessInfo.userName>>, And<Users.isApproved, Equal<True>>>,
OrderBy<Asc<Users.username>>>.Select(Base);
// populate the approver 1 with the current logged in user
if (currentUser != null && batchExt != null && row.Hold == false &&
string.IsNullOrEmpty(batchExt.UsrApprover1) &&
string.IsNullOrEmpty(batchExt.UsrApprover2))
{
batchExt.UsrApprover1 = currentUser.FullName;
}
// populate approver 2 with the current logged in user, it must be different than approver 2
if (currentUser != null && batchExt != null && row.Hold == false &&
!string.IsNullOrEmpty(batchExt.UsrApprover1) &&
string.IsNullOrEmpty(batchExt.UsrApprover2) && batchExt.UsrApprover1 != currentUser.FullName)
//(batchExt.UsrApprover1 != batchExt.UsrApprover2 && batchExt.UsrApprover1 != currentUser.FullName)))
{
batchExt.UsrApprover2 = currentUser.FullName;
}
// set the Release action
if (currentUser != null && batchExt != null && row.Hold == false)
base.Base.Release.SetEnabled(!string.IsNullOrEmpty(batchExt.UsrApprover1) && !string.IsNullOrEmpty(batchExt.UsrApprover2));
}
在 RowSelected 中更新自定义字段后,保存按钮未启用。我无法保存更改。如果我让 IsDirty = true 启用保存但没有数据保存到数据库。我还做了一个测试,看看它是否真的写入了数据库,如果我更改了付款的描述并保存数据是否保存到数据库中。如果启用了自定义字段并且我输入了一些内容,它会保存到数据库中。
我也尝试了e.Cache.RaiseFieldUpdated<CABatchExt.usrApprover1>(row, currentUser.FullName); 和e.Cache.SetValueExt<CABatchExt.usrApprover1>(row, currentUser.FullName);,结果相同。
我认为问题在于该字段从未启用,并且当用户打开屏幕时,不会进行任何修改,也不会保留任何数据。我需要一种模拟字段跳出或强制更改字段的方法。
【问题讨论】:
标签: acumatica