Skip to main content
Solved

Extending GLTran DAC to have customer/vendor class.

  • 13 December 2022
  • 7 replies
  • 165 views

Forum|alt.badge.img

Hello,

I am trying to add the customer class to the GL301000 Journal transaction form. As you can see from the code, I have created a DAC extension for GLTran, I have also added a database column to the GLTran table called “UsrMissionCustomerClassID” as an int. So, Currently I am just trying to get the refenceID to show up.

So far I have been unable to get anything to show up, and when I run the debugger in Visual Studio

value is always set to null. 

I have read through the T series dev guides but I am unsure what to apply to this DAC extension.

Any guidance would be greatly appreciated!

Thank you in advance.

namespace PX.Objects.GL
{
    public class GLTranExt : PXCacheExtension<PX.Objects.GL.GLTran>
  {

        public abstract class usrMissionCustomerClassID : PX.Data.BQL.BqlInt.Field<usrMissionCustomerClassID> { }
        public Int32? _UsrMissionCustomerClassID;

        [PXDBInt()]
        [PXUIField(DisplayName = "Customer Account Class", Enabled = false)]
        [PXSelector(typeof(Search<BAccountR.bAccountID>), SubstituteKey = typeof(BAccountR.acctCD))]

        public virtual Int32? UsrMissionCustomerClassID
        {
            get { return this._UsrMissionCustomerClassID; }
            set { this._UsrMissionCustomerClassID = value; }
        }

    }
}

 

Best answer by aaghaei

@AidenMission @ddunn 

 

What you are asking for is a little bit more complex than just simply adding a DAC field and getting the result in GL Transaction Screen. Here I have added some code for it but I have not tested it. Hopefully, it will work or will give you a head start to warp it up yourself.

using PX.Data;
using PX.Objects.AP;
using PX.Objects.AR;

namespace PX.Objects.GL
{
    // DAC Ext
    [PXNonInstantiatedExtension]
    public sealed class GLTranExt : PXCacheExtension<PX.Objects.GL.GLTran>
    {
        public static bool IsActive() => true;

        #region UsrClassName
        public abstract class usrClassName : PX.Data.BQL.BqlString.Field<usrClassName> { }
        [PXString(60, IsUnicode = true)]
        [PXUIField(DisplayName = "Class Name", Enabled = false, Visible = true)]
        public string UsrClassName { get; set; }
        #endregion
    }

    // Graph Ext
    public class JournalEntryExt : PXGraphExtension<PX.Objects.GL.JournalEntry>
    {
        public static bool IsActive() => true;

        protected void _(Events.FieldSelecting<GLTran, GLTranExt.usrClassName> e)
        {
            var row = (GLTran)e.Row;
            if (row == null) return;

            if (row.Module == "AR" && row.ReferenceID != null)
            {
                Customer account = PXSelect<Customer,
                    Where<Customer.bAccountID, Equal<Required<Customer.bAccountID>>>>.Select(Base, row.ReferenceID);

                if (account != null) return;
                CustomerClass accountClass = PXSelect<CustomerClass,
                    Where<CustomerClass.customerClassID, Equal<Required<CustomerClass.customerClassID>>>>.Select(Base, account.CustomerClassID);

                if (accountClass == null) return;
                e.ReturnValue = accountClass.Descr;
            }

            if (row.Module == "AP" && row.ReferenceID != null)
            {
                Vendor account = PXSelect<Vendor,
                    Where<Vendor.bAccountID, Equal<Required<Vendor.bAccountID>>>>.Select(Base, row.ReferenceID);

                if (account != null) return;
                VendorClass accountClass = PXSelect<VendorClass,
                    Where<VendorClass.vendorClassID, Equal<Required<VendorClass.vendorClassID>>>>.Select(Base, account.VendorClassID);

                if (accountClass == null) return;
                e.ReturnValue = accountClass.Descr;
            }
        }
    }

    //Do not forget to ADD the "UsrClassName" to the Grid in your screen and set the CommitChanges = True 
}

 

 

View original
Did this topic help you find an answer to your question?

7 replies

Forum|alt.badge.img+5
  • Captain II
  • 505 replies
  • December 13, 2022

Based on what you’ve described, you’ve added the column to the database table and the DAC.  The value, however, will be null until you assign it.

What’s your intention on how to populate the contents of this field?  Automatically based on the value of another field in the same record? Or during data entry?


Forum|alt.badge.img
  • Author
  • Jr Varsity II
  • 25 replies
  • December 14, 2022

Hey @ddunn,

Yeah that makes sense.

I am trying to make it happen automatically, I am thinking that I can pull form the referenceID column and work my way back to a customer class with a search. 

at one point I was trying to us just:

[PXFormula(GLTran.referneceID)]

and that way filling in the referenceID, however when I tried to expand it into a search I couldn’t get it to show anything.


aaghaei
Captain II
Forum|alt.badge.img+9
  • Captain II
  • 1178 replies
  • Answer
  • December 15, 2022

@AidenMission @ddunn 

 

What you are asking for is a little bit more complex than just simply adding a DAC field and getting the result in GL Transaction Screen. Here I have added some code for it but I have not tested it. Hopefully, it will work or will give you a head start to warp it up yourself.

using PX.Data;
using PX.Objects.AP;
using PX.Objects.AR;

namespace PX.Objects.GL
{
    // DAC Ext
    [PXNonInstantiatedExtension]
    public sealed class GLTranExt : PXCacheExtension<PX.Objects.GL.GLTran>
    {
        public static bool IsActive() => true;

        #region UsrClassName
        public abstract class usrClassName : PX.Data.BQL.BqlString.Field<usrClassName> { }
        [PXString(60, IsUnicode = true)]
        [PXUIField(DisplayName = "Class Name", Enabled = false, Visible = true)]
        public string UsrClassName { get; set; }
        #endregion
    }

    // Graph Ext
    public class JournalEntryExt : PXGraphExtension<PX.Objects.GL.JournalEntry>
    {
        public static bool IsActive() => true;

        protected void _(Events.FieldSelecting<GLTran, GLTranExt.usrClassName> e)
        {
            var row = (GLTran)e.Row;
            if (row == null) return;

            if (row.Module == "AR" && row.ReferenceID != null)
            {
                Customer account = PXSelect<Customer,
                    Where<Customer.bAccountID, Equal<Required<Customer.bAccountID>>>>.Select(Base, row.ReferenceID);

                if (account != null) return;
                CustomerClass accountClass = PXSelect<CustomerClass,
                    Where<CustomerClass.customerClassID, Equal<Required<CustomerClass.customerClassID>>>>.Select(Base, account.CustomerClassID);

                if (accountClass == null) return;
                e.ReturnValue = accountClass.Descr;
            }

            if (row.Module == "AP" && row.ReferenceID != null)
            {
                Vendor account = PXSelect<Vendor,
                    Where<Vendor.bAccountID, Equal<Required<Vendor.bAccountID>>>>.Select(Base, row.ReferenceID);

                if (account != null) return;
                VendorClass accountClass = PXSelect<VendorClass,
                    Where<VendorClass.vendorClassID, Equal<Required<VendorClass.vendorClassID>>>>.Select(Base, account.VendorClassID);

                if (accountClass == null) return;
                e.ReturnValue = accountClass.Descr;
            }
        }
    }

    //Do not forget to ADD the "UsrClassName" to the Grid in your screen and set the CommitChanges = True 
}

 

 


aaghaei
Captain II
Forum|alt.badge.img+9
  • Captain II
  • 1178 replies
  • December 15, 2022

EDIT

@AidenMission i guess you noticed it but I meant to check == null then return not != null for return. 😝


Forum|alt.badge.img
  • Author
  • Jr Varsity II
  • 25 replies
  • December 15, 2022

 Thank you @aaghaei I haven’t gotten a chance to test it yet, ill be sure to make that little change when I can :^)


Forum|alt.badge.img
  • Author
  • Jr Varsity II
  • 25 replies
  • December 16, 2022

Reporting for completeness sakes, The customization works exactly as expected!

As @aaghaei said you have to fix the null checks against account, so I am going to paste the fixed code here to make it easier for others to see.

using PX.Data;
using PX.Objects.AP;
using PX.Objects.AR;

namespace PX.Objects.GL
{

    [PXNonInstantiatedExtension]
    public sealed class GLTranExt : PXCacheExtension<PX.Objects.GL.GLTran>
    {
        public static bool IsActive() => true;

        #region UsrMissionCustomerClass
        public abstract class usrMissionCustomerClass : PX.Data.BQL.BqlString.Field<usrMissionCustomerClass> { }
        [PXString(60, IsUnicode = true)]
        [PXUIField(DisplayName = "Customer Class", Enabled = false, Visible = true)]
        public string UsrMissionCustomerClass { get; set; }
        #endregion
    }

    // Graph Ext
    public class JournalEntryExt : PXGraphExtension<PX.Objects.GL.JournalEntry>
    {
        public static bool IsActive() => true;

        protected void _(Events.FieldSelecting<GLTran, GLTranExt.usrMissionCustomerClass> e)
        {
            var row = (GLTran)e.Row;
            if (row == null) return;

            if (row.Module == "AR" && row.ReferenceID != null)
            {
                Customer account = PXSelect<Customer,
                    Where<Customer.bAccountID, Equal<Required<Customer.bAccountID>>>>.Select(Base, row.ReferenceID);

                if (account == null) return;
                CustomerClass accountClass = PXSelect<CustomerClass,
                    Where<CustomerClass.customerClassID, Equal<Required<CustomerClass.customerClassID>>>>.Select(Base, account.CustomerClassID);

                if (accountClass == null) return;
                e.ReturnValue = accountClass.Descr;
            }

            if (row.Module == "AP" && row.ReferenceID != null)
            {
                Vendor account = PXSelect<Vendor,
                    Where<Vendor.bAccountID, Equal<Required<Vendor.bAccountID>>>>.Select(Base, row.ReferenceID);

                if (account == null) return;
                VendorClass accountClass = PXSelect<VendorClass,
                    Where<VendorClass.vendorClassID, Equal<Required<VendorClass.vendorClassID>>>>.Select(Base, account.VendorClassID);

                if (accountClass == null) return;
                e.ReturnValue = accountClass.Descr;
            }
        }
    }

    //Do not forget to ADD the "UsrClassName" to the Grid in your screen and set the CommitChanges = True
}

 

 


aaghaei
Captain II
Forum|alt.badge.img+9
  • Captain II
  • 1178 replies
  • December 16, 2022

@AidenMission happy to hear you got what you needed.


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings