简体   繁体   中英

Unable to save data to custom field on Account Details Grid

I have a custom button that updates a custom boolean field on selected rows. The field is being updated, but the changes are not committing to the database. The error below is being thrown on the last line gltran.Persist()

public class AccountByPeriodEnq_Extension : PXGraphExtension<AccountByPeriodEnq>
{
    public PXAction<AccountByPeriodFilter> Recon;

    [PXButton(CommitChanges = true)]
    [PXUIField(DisplayName = "Reconcile")]
    protected void recon()
    {
        PXCache gltran = Base.Caches[typeof(GLTran)];
        foreach (GLTran tran in gltran.Updated)
        {
            if (tran.Selected == true)
            {
                GLTranExt gltranEx = tran.GetExtension<GLTranExt>();
                if (gltranEx.UsrRecon == true) gltranEx.UsrRecon = false;
                else gltranEx.UsrRecon = true;
                gltran.Update(tran);
                gltran.Persist(PXDBOperation.Update);
            }
        }
    }
}

Error:

{"Error: 'AmtReleasedClearedDr' cannot be empty."}

Stack:

" at PX.Data.PXDefaultAttribute.RowPersisting(PXCache sender, PXRowPersistingEventArgs e)\\r\\n at PX.Data.PXCache.OnRowPersisting(Object item, PXDBOperation operation)\\r\\n at PX.Data.PXCache 1.PersistInserted(Object row)\\r\\n at PX.Data.PXCache 1.Persist(PXDBOperation operation)\\r\\n at PX.Data.PXRowPersisting.Invoke(PXCache sender, PXRowPersistingEventArgs e)\\r\\n at PX.Data.PXCache.OnRowPersisting(Object item, PXDBOperation operation)\\r\\n at PX.Data.PXCache 1.PersistUpdated(Object row)\\r\\n at PX.Objects.CA.CashTranIDAttribute.RowPersisting(PXCache sender, PXRowPersistingEventArgs e) in F:\\\\Bld2\\\\AC-FULL61U8-JOB1\\\\sources\\\\WebSites\\\\Pure\\\\PX.Objects\\\\CA\\\\Descriptor\\\\CashTranIDAttribute.cs:line 828\\r\\n at PX.Objects.GL.GLCashTranIDAttribute.RowPersisting(PXCache sender, PXRowPersistingEventArgs e) in F:\\\\Bld2\\\\AC-FULL61U8-JOB1\\\\sources\\\\WebSites\\\\Pure\\\\PX.Objects\\\\GL\\\\Descriptor\\\\Attribute.cs:line 3462\\r\\n at PX.Data.PXCache.OnRowPersisting(Object item, PXDBOperation operation)\\r\\n at PX.Data.PXCache 1.PersistUpdated(Object row)\\r\\n at PX.Objects.CA.CashTranIDAttribute.RowPersisting(PXCache sender, PXRowPersistingEventArgs e) in F:\\\\Bld2\\\\AC-FULL61U8-JOB1\\\\sources\\\\WebSites\\\\Pure\\\\PX.Objects\\\\CA\\\\Descriptor\\\\CashTranIDAttribute.cs:line 828\\r\\n at PX.Objects.GL.GLCashTranIDAttribute.RowPersisting(PXCache sender, PXRowPersistingEventArgs e) in F:\\\\Bld2\\\\AC-FULL61U8-JOB1\\\\sources\\\\WebSites\\\\Pure\\\\PX.Objects\\\\GL\\\\Descriptor\\\\Attribute.cs:line 3462\\r\\n at PX.Data.PXCache.OnRowPersisting(Object item, PXDBOperation operation)\\r\\n at PX.Data.PXCache 1.PersistUpdated(Object row)\\r\\n at PX.Data.PXCache`1.Persist(PXDBOperation operation)\\r\\n at PX.Objects.GL.AccountByPeriodEnq_Extension.recon() in c:\\Program Files (x86)\\Acumatica ERP\\AcumaticaERP\\App_Code\\Caches\\AccountByPeriodEnq.cs:line 43"

-----------------------------------------------------------------------

Working Code (Thank you Patrick):

public class AccountByPeriodEnq_Extension:PXGraphExtension<AccountByPeriodEnq>
{
    public PXAction<AccountByPeriodFilter> Recon;

    [PXButton(CommitChanges = true)]
    [PXUIField(DisplayName = "Reconcile")]
    protected void recon()
    {
        PXCache gltran = Base.Caches[typeof(GLTran)];
        foreach (GLTran tran in gltran.Updated)
        {
            if (tran.Selected == true)
            {
                GLTranExt glTranEx = tran.GetExtension<GLTranExt>();
                var recon = (glTranEx.UsrRecon == true) ? false : true;

                PXDatabase.Update<GLTran>(
                    new PXDataFieldAssign<GLTranExt.usrRecon>(recon),
                    new PXDataFieldRestrict<GLTran.batchNbr>(tran.BatchNbr),
                    new PXDataFieldRestrict<GLTran.lineNbr>(tran.LineNbr)
                );                 
            }
        }           
    }        
}    

You might try something like this code in your button. This will update without triggering other events.

PXDatabase.Update<GLTran>(
   new PXDataFieldAssign<GLTranExtension.UsrRecon >(bool_var),
   new PXDataFieldRestrict<GLTran.batchnbr>(tran.batchnbr),
   new PXDataFieldRestrict<GLTran.lineNbr>(tran.LineNbr)
);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM