Search code examples
acumatica

How can I process a user field from Bills and Adjustments to Journal Transactions during the Release process?


I've got a customization that adds a user field (same type and name) to both Bills and Adjustments (APTran) and Journal Transactions (GLTran). What I'd like to do is have the APTran user field's value (manually entered) automatically transmitted to GLTran during the Release process.

I've been able to slap together a customization based on what I've found here on Stack Overflow, as follows:

public class APReleaseProcessExt : PXGraphExtension<APReleaseProcess>
{
    public static bool IsActive() { return true; }

    #region Event Handlers
    public delegate List<APRegister> ReleaseInvoiceDelegate(JournalEntry je
                                                                         ,ref APRegister doc
                                                                         ,PXResult<APInvoice, CurrencyInfo, Terms, Vendor> res
                                                                         ,Boolean isPrebooking
                                                                         ,ref List<INRegister> inDocs);

    [PXOverride]
    public List<APRegister> ReleaseInvoice(JournalEntry je, ref APRegister doc, PXResult<APInvoice, CurrencyInfo, Terms, Vendor> res, bool isPrebooking, ref List<INRegister> inDocs, ReleaseInvoiceDelegate baseMethod)
    {

        je.RowInserting.AddHandler<GLTran>((s, a) =>
        {
            var gltran = (GLTran)a.Row;
            var apTran = (APTran)PXResult<APTran>.Current;

            if (gltran != null && gltran.TranLineNbr != null &&
                apTran != null && apTran.TranType == gltran.TranType &&
                apTran.RefNbr == gltran.RefNbr && apTran.LineNbr == gltran.TranLineNbr)
            {
                var grantid = apTran.GetExtension<APTranExt>().UsrGrantID;
                if (!string.IsNullOrEmpty(grantid))
                    gltran.GetExtension<GLTranExt>().UsrGrantID = grantid;
            }
        });

        return baseMethod(je, ref doc, res, isPrebooking, ref inDocs);
    }

    #endregion
}

But this doesn't work. I think I'm on the right track, but there must be something I'm missing.

Any help would be appreciated.

Thanks much...


Solution

  • Using the following Stack Overflow post as a template:

    Customize Release AP Document in Acumatica System

    I modified the code to fit my requirements. I test this and it appears to work:

    public class APRelaseProcessExt : PXGraphExtension<APReleaseProcess>
    {
        public static bool IsActive() { return true; }
    
        public delegate List<APRegister> ReleaseDocProcDel(JournalEntry je, APRegister doc, bool isPrebooking, out List<INRegister> inDocs);
        [PXOverride]
        public virtual List<APRegister> ReleaseDocProc(JournalEntry je, APRegister doc, bool isPrebooking, out List<INRegister> inDocs, ReleaseDocProcDel del)
        {
            je.RowInserting.AddHandler<GLTran>((sender, e) =>
            {
                GLTran glTran = e.Row as GLTran;
    
                //APInvoice api = PXSelect<APInvoice, Where<APInvoice.refNbr, Equal<Required<GLTran.refNbr>>, And<APInvoice.docType, Equal<Required<GLTran.tranType>>>>>.Select(sender.Graph, glTran.RefNbr, glTran.TranType);
                APTran apTran = PXSelect<APTran, 
                                Where<APTran.refNbr, Equal<Required<APTran.refNbr>>, 
                                And<APTran.tranType, Equal<Required<APTran.tranType>>>>>.Select(sender.Graph, glTran.RefNbr, glTran.TranType);
    
                if (apTran != null && apTran.RefNbr != null)
                {
                    GLTranExt glTex = PXCache<GLTran>.GetExtension<GLTranExt>(glTran);
                    APTranExt apTex = PXCache<APTran>.GetExtension<APTranExt>(apTran);
                    glTex.UsrGrantID = apTex.UsrGrantID; //api
                }
            });
            return del(je, doc, isPrebooking, out inDocs);
        }
    }