-->

How to Customize screen Release AP Documents (AP50

2019-07-13 02:17发布

问题:

I have a problem in customize screen Release AP Documents (screnid = AP501000). In case I have already create some additional fields in screen AP Bill And Adjusment, I was created 2 fields in DAC APTran (UsrJobOrderNbr and usrNoSeriFaktur). I create DAC Extension as named APTranExtension. and this below is the sintaks :

using PX.Objects.CR;
using PX.Objects.EP;
using PX.Objects.FA;
using PX.Objects.PO;
using System;
using PX.Data;
using PX.Objects.GL;
using PX.Objects.CM;
using PX.Objects.CS;
using PX.Objects.IN;
using PX.Objects.TX;
using PX.Objects.DR;
using PX.Objects.PM;
using System.Collections.Generic;
using PX.Objects;
using PX.Objects.AP;

namespace SGLCustomization
{
   [Serializable]
   public class APTranExtension: PXCacheExtension<PX.Objects.AP.APTran>
   {
       #region UsrJobOrderNbr`enter code here`
       public abstract class usrJobOrderNbr : IBqlField{}
       [PXDBString(25, IsFixed = true, IsUnicode = true)]
       [PXUIField(DisplayName="Job Order Nbr")]
       [PXSelector(typeof(Search<JobOrderNbr.jobOrderNbrCD,
                        Where<JobOrderNbr.status,
                            Equal<statusActive>>>),
              typeof(JobOrderNbr.customerID),
              typeof(JobOrderNbr.status),
              typeof(JobOrderNbr.usrJobOrderNoRef))]
      public string UsrJobOrderNbr
      {
          get;
          set;
      }

      #endregion
  }
} 

I also create DAC Extension as named APTaxTranExtension, and this below is the sintaks :

using PX.Objects.CR;
using PX.Objects.EP;
using PX.Objects.FA;
using PX.Objects.PO;
using System;
using PX.Data;
using PX.Objects.GL;
using PX.Objects.CM;
using PX.Objects.CS;
using PX.Objects.IN;
using PX.Objects.TX;
using PX.Objects.DR;
using PX.Objects.PM;
using System.Collections.Generic;
using PX.Objects;
using PX.Objects.AP;
using PX.Objects.AR;

namespace SGLCustomization
{
   [Serializable]
   public class APTaxTranExtension: PXCacheExtension<PX.Objects.AP.APTaxTran>
   {
     #region UsrNoSeriFaktur
     public abstract class usrNoSeriFaktur : IBqlTable{}
     [PXDBString(50, IsFixed = true)]
     [PXUIField(DisplayName = "No Seri Faktur / Additional Narration")]
     public string UsrNoSeriFaktur { get; set; }
     #endregion
   }
}

I also create Extension DAC in GLTranExtension, to store values from APTranExtension and APTaxTranExtension. This below is the sintaks of my GLTranExtension :

using System;
using PX.Data;
using PX.Objects.CM;
using PX.Objects.CS;
using PX.Objects.PM;
using PX.Objects.CR;
using PX.Objects.TX;
using System.Collections.Generic;
using PX.Objects;
using PX.Objects.GL;

namespace SGLCustomization
{
   [Serializable]
  public class GLTranExtension: PXCacheExtension<PX.Objects.GL.GLTran>
  {
      #region UsrJobOrderNbr

      public abstract class usrJobOrderNbr : IBqlField{}
      [PXDBString(25, IsFixed = true, IsUnicode = true)]
      [PXUIField(DisplayName="Job Order Nbr")]
      [PXSelector(typeof(Search<JobOrderNbr.jobOrderNbrCD,
                        Where<JobOrderNbr.status,
                            Equal<statusActive>>>),
                //typeof(JobOrderNbr.jobOrderNbrCD),
                typeof(JobOrderNbr.customerID),
                typeof(JobOrderNbr.status))]
      public string UsrJobOrderNbr{get;set;}
      #endregion

      #region UsrNoSeriFaktur
      public abstract class usrNoSeriFaktur : IBqlTable { }
      [PXDBString(75, IsFixed = true)]
      [PXUIField(DisplayName = "No Seri Faktur / Additional Narration")]
      public string UsrNoSeriFaktur { get; set; }
      #endregion

      #region UsrInvoiceNbr
      public abstract class usrInvoiceNbr : IBqlTable { }
      [PXDBString(60, IsFixed = true)]
      [PXUIField(DisplayName = "Vendor Ref. / Customer Order")]
      public string UsrInvoiceNbr { get; set; }
      #endregion
  }
}

My goal is when I input transactions and then I release the document in screen Release AP Document (AP501000), all values in my new additional fields already sent into Journal Transaction screen (GL301000) also.

I already create APReleaseProcessExtension BLC to provide it, but it didn't work. This below is my APReleaseProcessExtension code :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using PX.Data;
using PX.Objects.AP;
using PX.Objects.GL;
using PX.Objects.CM;
using PX.Objects.CA;
using PX.Objects.CR;
using PX.Objects.CS;
using PX.Objects.CT;
using PX.Objects.PM;
using SGLCustomization;
using SGLCustomization1;

namespace SGLCustomization1
{

  public class APReleaseProcessExtension: PXGraphExtension<APReleaseProcess>
  {
      public delegate List<APRegister> ReleaseDocProcDel(JournalEntry je, ref APRegister doc, PXResult<APInvoice, CurrencyInfo, Terms, Vendor, Account> res, out PMRegister pmDoc);
      public List<APRegister> ReleaseDocProc(JournalEntry je, ref APRegister doc, PXResult<APInvoice, CurrencyInfo, Terms, Vendor, Account> res, out PMRegister pmDoc, ReleaseDocProcDel del)
      {
          je.RowInserting.AddHandler<GLTran>((sender, e) =>
          {
              GLTran glTran = e.Row as GLTran;
              APTran apTran = PXResult<APTran>.Current;
              if (glTran != null && apTran != null)
              {
                  APTranExtension apTex = PXCache<APTran>.GetExtension<APTranExtension>(apTran);
                  if (apTran != null && apTex.UsrJobOrderNbr != null)
                  {
                      GLTranExtension glTex = PXCache<GLTran>.GetExtension<GLTranExtension>(glTran);
                      glTex.UsrJobOrderNbr = apTex.UsrJobOrderNbr;
                  }
              }

              APInvoice api = PXResult<APInvoice>.Current;
              if (api != null && api.InvoiceNbr != null)
              {
                  GLTranExtension glTex = PXCache<GLTran>.GetExtension<GLTranExtension>(glTran);
                  glTex.UsrInvoiceNbr = api.InvoiceNbr;
              }

              APTaxTran apTax = PXResult<APTaxTran>.Current;
              if (apTax != null)
              { 
                  APTaxTranExtension apTaxEx = PXCache<APTaxTran>.GetExtension<APTaxTranExtension>(apTax);
                  if (apTax != null && apTaxEx.UsrNoSeriFaktur != null)
                  {
                      GLTranExtension glTex = PXCache<GLTran>.GetExtension<GLTranExtension>((GLTran)e.Row);
                      glTex.UsrNoSeriFaktur = apTaxEx.UsrNoSeriFaktur;

                  }
              }
          });
          return del(je, ref doc, res, out pmDoc);
      }
    #region Event Handlers
    #endregion
  }
}

Please help me to provide my goal,

回答1:

You are moving into right direction but you've forgot to add [PXOverride] attribute. Without PXOverrideAttribute your method ReleaseDocProc will not be called. ReleaseDocProc of the base graph will be called instead.

You should always specify PXOverrideAttribute for methods that were overrided in extensions. Note that event handlers should not be marked with PXOverrideAttribute.

So the final code will look like that(I've modified methods signature as it was not compatible with the base method's signature in Acu 5.3U6):

public class APReleaseProcessExtension : PXGraphExtension<APReleaseProcess>
{
    public delegate List<APRegister> ReleaseDocProcDel(JournalEntry je, ref APRegister doc, PXResult<APInvoice, CurrencyInfo, Terms, Vendor> res, bool isPrebooking, out List<INRegister> inDocs);
    [PXOverride]
    public List<APRegister> ReleaseDocProc(JournalEntry je, ref APRegister doc, PXResult<APInvoice, CurrencyInfo, Terms, Vendor> res, bool isPrebooking, out List<INRegister> inDocs, ReleaseDocProcDel del)
    {
        je.RowInserting.AddHandler<GLTran>((sender, e) =>
        {
            GLTran glTran = e.Row as GLTran;
            APTran apTran = PXResult<APTran>.Current;
            if (glTran != null && apTran != null)
            {
                APTranExtension apTex = PXCache<APTran>.GetExtension<APTranExtension>(apTran);
                if (apTran != null && apTex.UsrJobOrderNbr != null)
                {
                    GLTranExtension glTex = PXCache<GLTran>.GetExtension<GLTranExtension>(glTran);
                    glTex.UsrJobOrderNbr = apTex.UsrJobOrderNbr;
                }
            }
        });
        return del(je, ref doc,  res,  isPrebooking, out inDocs);
    }
}

I've also removed TaxTran and Invoice related extensions from this code to simplify it. You can easily return it.

I hope this answers your question.



标签: acumatica