0
votes

This is my first development after completing the Acumatica Developer training.

I am busy with a user approval on the Batch Payment screen (AP305000). The idea is when the current user opens the Batch Payment, the custom fields default to the current user name. I added 2 custom fields for the approver. There are 2 Approvers.

Batch Payment

    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
    }

The custom fields are never enabled and I populate them in the RowSelected event:

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

After the custom fields are updated in the RowSelected the Save button is not enabled. I can't Save the changes. If I make IsDirty = true the Save is enabled but no data is saved to the database. I also did a test to see if it actually writes to the database, if I change the description on the payment and Save the data is saved to the database. If the custom fields are enabled and I type something it saves to the database.

I also tried e.Cache.RaiseFieldUpdated<CABatchExt.usrApprover1>(row, currentUser.FullName); and e.Cache.SetValueExt<CABatchExt.usrApprover1>(row, currentUser.FullName); with same result. I think the problem is because the field are never enabled and when a user opens the screen no modification takes place and no data is persisted. I need a way of simulating the tabbing out of a field or forcing a field change.

1

1 Answers

0
votes

You can try updating the cache like this

this.Base.CABatchDetail.Update(row);

Add this code of your code

You can also try to allow for updates:

  this.Base.CABatchDetail.AllowUpdate = true;