Acumatica 发布过程完成后,如何在ARCashSale上保存自定义字段?

Acumatica 发布过程完成后,如何在ARCashSale上保存自定义字段?,acumatica,Acumatica,当我发布现金销售凭证时,在所有内容都成功验证并创建总账批处理后,我执行创建第二个总账批处理的代码,该代码处理与现金销售相关的其他交易。创建该批次后,我还想在现金销售凭证上保存第二个总账批次的参考编号。当我试图保存它时,我得到一个错误: 下面是我的代码,它覆盖了正常的发布过程: public delegate IEnumerable ReleaseDelegate(PXAdapter adapter); [PXOverride] public IEnumerable Release(PXAdap

当我发布现金销售凭证时,在所有内容都成功验证并创建总账批处理后,我执行创建第二个总账批处理的代码,该代码处理与现金销售相关的其他交易。创建该批次后,我还想在现金销售凭证上保存第二个总账批次的参考编号。当我试图保存它时,我得到一个错误:

下面是我的代码,它覆盖了正常的发布过程:

public delegate IEnumerable ReleaseDelegate(PXAdapter adapter);
[PXOverride]
public IEnumerable Release(PXAdapter adapter, ReleaseDelegate baseMethod)
{
    ARCashSale cashSale = Base.Document.Current;

    PXGraph.InstanceCreated.AddHandler<JournalEntry>(delegate (JournalEntry oldJournalEntry)
    {
        oldJournalEntry.RowPersisted.AddHandler<Batch>(delegate (PXCache sender, PXRowPersistedEventArgs e)
        {
            Batch oldBatch = oldJournalEntry.BatchModule.Current;

            if (oldBatch != null && isCreated == false && e.Operation == PXDBOperation.Insert && e.TranStatus == PXTranStatus.Completed)
            {
                isCreated = true;
                if (CFBSAdjustments.Select().Count > 0)
                {

                    JournalEntry newJournalEntry = PXGraph.CreateInstance<JournalEntry>();

                    Batch newBatch = new Batch();

                    newBatch = newJournalEntry.BatchModule.Insert(newBatch);

                    Customer customer = PXSelect<Customer, Where<Customer.bAccountID, Equal<Required<Customer.bAccountID>>>>.Select(Base, cashSale.CustomerID);
                    newBatch.Description = "Fund Entry for Cash Sales Reference " + cashSale.RefNbr;
                    newBatch.FinPeriodID = oldBatch.FinPeriodID;
                    newBatch.LedgerID = oldBatch.LedgerID;
                    newBatch.DateEntered = oldBatch.DateEntered;

                    decimal? debit = 0;
                    decimal? credit = 0;
                    foreach (CFBSCashSalesAdjustment row in CFBSAdjustments.Select())
                    {
                        GLTran tran = newJournalEntry.GLTranModuleBatNbr.Insert();

                        tran.SummPost = true;
                        tran.BranchID = cashSale.BranchID;
                        tran.TranType = GLTran.tranClass.Normal;
                        tran.TranClass = GL.Messages.RoundingDiff;
                        tran.LedgerID = newBatch.LedgerID;
                        tran.FinPeriodID = newBatch.FinPeriodID;
                        tran.TranDate = newBatch.DateEntered;
                        tran.CuryInfoID = Base.currencyinfo.Current.CuryInfoID;

                        tran.AccountID = row.Account;
                        tran.SubID = row.Subaccount;
                        tran.DebitAmt = row.DebitAmt;
                        tran.CuryDebitAmt = row.DebitAmt;
                        debit += row.DebitAmt;
                        tran.CreditAmt = row.CreditAmt;
                        tran.CuryCreditAmt = row.CreditAmt;
                        credit += row.CreditAmt;
                        tran.RefNbr = row.CashSalesRefNbr;
                        tran.TranDesc = customer.AcctCD + " - " + customer.AcctName;
                        newJournalEntry.GLTranModuleBatNbr.Update(tran);
                    }

                    newBatch = newJournalEntry.BatchModule.Update(newBatch);

                    if (GLSetup.Current.GetExtension<GLSetupExt>().UsrAutoRelease == true)
                    {
                        newJournalEntry.BatchModule.Current.Hold = false;
                        newJournalEntry.release.Press();
                    }

                    newJournalEntry.Save.Press();
                    if (isCreated)
                        isCreated = false;

                    cashSale.GetExtension<ARRegisterExt>().UsrFundBatch = newJournalEntry.BatchModule.Current.BatchNbr;
                    //Base.Document.Current.GetExtension<ARRegisterExt>().UsrFundBatch = newJournalEntry.BatchModule.Current.BatchNbr;
                    //Base.dummy_CATran.View.RequestRefresh();
                    Base.Document.Update(cashSale);
                    //TODO - Figure out why the fund batch isn't saving to the Cash Sale
                    Base.Actions.PressSave();
                    //Base.dummy_CATran.Cache.ClearQueryCache();
                    //Base.Persist(typeof(ARCashSale), PXDBOperation.Update);
                }
            }
        });

    });
    return baseMethod(adapter);
}
public委托IEnumerable ReleaseDelegate(PXAdapter);
[PXOverride]
公共IEnumerable发布(PXAdapter适配器、ReleaseDelegate baseMethod)
{
ARCashSale cashSale=Base.Document.Current;
PXGraph.InstanceCreated.AddHandler(委托(JournalEntry-oldJournalEntry)
{
oldJournalEntry.RowPersisted.AddHandler(委托(PXCache发送方,PXRowPersistedEventArgs e)
{
Batch oldBatch=oldJournalEntry.BatchModule.Current;
if(oldBatch!=null&&isCreated==false&&e.Operation==PXDBOperation.Insert&&e.TranStatus==PXTranStatus.Completed)
{
isCreated=true;
如果(CFBSAdjustments.Select().Count>0)
{
JournalEntry newJournalEntry=PXGraph.CreateInstance();
批次newBatch=新批次();
newBatch=newJournalEntry.BatchModule.Insert(newBatch);
Customer=PXSelect.Select(Base,cashSale.CustomerID);
newBatch.Description=“现金销售参考的资金分录”+cashSale.RefNbr;
newBatch.FinPeriodID=oldBatch.FinPeriodID;
newBatch.LedgerID=oldBatch.LedgerID;
newBatch.DateEntered=oldBatch.DateEntered;
十进制?借方=0;
十进制?信用=0;
foreach(CFBSAdjustments.Select()中的CFBSCashSalesAdjustment行)
{
GLTran tran=newJournalEntry.GLTranModuleBatNbr.Insert();
tran.SummPost=真;
tran.BranchID=cashSale.BranchID;
tran.TranType=GLTran.tranClass.Normal;
tran.TranClass=GL.Messages.RoundingDiff;
tran.LedgerID=newBatch.LedgerID;
tran.FinPeriodID=newBatch.FinPeriodID;
tran.TranDate=输入的newBatch.date;
tran.CuryInfoID=Base.currencyinfo.Current.CuryInfoID;
tran.AccountID=行.Account;
tran.SubID=行子科目;
tran.DebitAmt=行.DebitAmt;
tran.CuryDebitAmt=row.DebitAmt;
借方+=第行借方;
tran.CreditAmt=行.CreditAmt;
tran.CuryCreditAmt=row.CreditAmt;
信用+=第行信用金额;
tran.RefNbr=row.CashSalesRefNbr;
tran.TranDesc=customer.AcctCD+“-”+customer.AcctName;
更新(tran);
}
newBatch=newJournalEntry.BatchModule.Update(newBatch);
if(GLSetup.Current.GetExtension().UsrAutoRelease==true)
{
newJournalEntry.BatchModule.Current.Hold=false;
newJournalEntry.release.Press();
}
newJournalEntry.Save.Press();
如果(已创建)
isCreated=false;
cashSale.GetExtension().UsrFundBatch=newJournalEntry.BatchModule.Current.BatchNbr;
//Base.Document.Current.GetExtension().UsrFundBatch=newJournalEntry.BatchModule.Current.BatchNbr;
//Base.dummy_CATran.View.RequestRefresh();
基础.文档.更新(现金销售);
//待办事项-找出为什么该基金批未保存到现金销售
Base.Actions.PressSave();
//Base.dummy_CATran.Cache.ClearQueryCache();
//Persist(typeof(ARCashSale),PXDBOperation.Update);
}
}
});
});
返回方法(适配器);
}
我用了所有不同的方法来保存参考编号。我曾经尝试过为BatchNbr字段添加一个字段更新处理程序,并以这种方式强制输入新的数字,但没有成功


编辑:我还注意到我无法在批处理DAC上成功设置扩展字段。例如,我有一行
newBatch.GetExtension().ExtRefNbr=cashSale.RefNbr
设置该文档中的ref-nbr,但每当我运行“NewJournal.Press.Save()”时,它都会将扩展字段的设置值更改为null。如果有人知道如何设置扩展字段,我可能可以使用它,而不是走另一条路,来完成我需要的工作。

第一步是尝试找出修改CATran DAC/dummy\u CATran DataView的内容。CFBSAdjustments DAC是否源自CATran?它看起来像一个定制的DAC。我会尝试声明一个CATran_RowUpdate事件,在其中放置一个断点,并检查调用堆栈以查找修改CATran的内容。CFBSAdjustments与CATran无关。我一点也不调整CATran。我假设它是屏幕,可能是ARCashSaleEntry的基本发布过程。编辑:我可以确认在执行自定义代码之前已更新CATran,并且自定义DAC不会影响CATran。