Skip to main content
Solved

How to add field to Customer Details AR402000

  • December 3, 2022
  • 7 replies
  • 261 views

Forum|alt.badge.img

Hi everyone,

I have a field named Project/Contract on Invoices and Memos (AR301000)

and I want bring this field to Grid on Customer Details screen

 

Could you please help me?

 

Thanks,

Khoi

Best answer by Naveen Boga

Hi @mrthanhkhoi  Please find the code here. I have verified it and it is working as expected.

 

public class ARDocumentResultExt : PXCacheExtension<ARDocumentResult>
    {
        #region UsrCustomerOrderNbr
        [PXString(50, IsUnicode = true)]
        [PXUIField(DisplayName = "Customer Order Nbr")]
        public virtual string UsrCustomerOrderNbr { get; set; }
        public abstract class usrCustomerOrderNbr : PX.Data.BQL.BqlString.Field<usrCustomerOrderNbr> { }
        #endregion
    }

    public class ARDocumentEnqExt : PXGraphExtension<ARDocumentEnq>
    {
        protected void ARDocumentResult_UsrCustomerOrderNbr_FieldSelecting(PXCache cache, PXFieldSelectingEventArgs e)
        {
            ARDocumentResult row = (ARDocumentResult)e.Row;
            if (row != null)
            {
                ARDocumentResultExt resext = row.GetExtension<ARDocumentResultExt>();
                ARInvoice invoiceObj = PXSelect<ARInvoice, Where<ARInvoice.docType, Equal<Required<ARInvoice.docType>>,
                                       And<ARInvoice.refNbr, Equal<Required<ARInvoice.refNbr>>>>>.Select(Base, row.DocType, row.RefNbr);
                if (invoiceObj != null)
                {
                    e.ReturnValue = invoiceObj.InvoiceNbr;
                }
            }
        }
    }

 

 

 

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

7 replies

Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • 3393 replies
  • December 3, 2022

Hi @mrthanhkhoi  It requires customization. Please find the customization steps below and hope this helps!

  1. Extend the ARDocumentEnq Graph
  2. Extend the ARDocumentResult DAC and the new field i.e.Project
  3. Add a new field selecting an event, in the extended graph and write the logic to load the Project field from the Invoices and Memos screen.

Forum|alt.badge.img
  • Author
  • Jr Varsity II
  • 85 replies
  • December 3, 2022

Hi @Naveen Boga,

Thank you for your hint but I the field isn’t shown data. Could you please advise me?

I tried with a simple field (single line of text) as an example with following step:

  • Create a custom field:
    public class ARDocumentResultExt : PXCacheExtension<PX.Objects.AR.ARDocumentEnq.ARDocumentResult>
        {
            #region UsrCustomerOrderNbr
            [PXString(50, IsUnicode = true)]
            [PXUIField(DisplayName = "Customer Order Nbr")]
    
            public virtual string UsrCustomerOrderNbr { get; set; }
            public abstract class usrCustomerOrderNbr : PX.Data.BQL.BqlString.Field<usrCustomerOrderNbr> { }
            #endregion
        }

     

  • Implement event handling
    protected void ARDocumentResult_UsrCustomerOrderNbr_FieldSelecting(PXCache cache, PXFieldSelectingEventArgs e)
            {
    
                var row = (ARDocumentResult)e.Row;
                if (row == null)
                {
                    return;
                }
                ARDocumentResultExt resext = row.GetExtension<ARDocumentResultExt>();
                ARInvoice invoiceObj = PXSelect<ARInvoice,
                    Where<ARInvoice.docType, Equal<Required<ARInvoice.docType>>,
                    And<ARInvoice.refNbr, Equal<Required<ARInvoice.refNbr>>>>>.Select(Base, row.DocType, row.RefNbr);
                if (invoiceObj == null) { return; }
                resext.UsrCustomerOrderNbr = invoiceObj.InvoiceNbr;
            }

 

This field is always empty

 

 


Forum|alt.badge.img
  • Author
  • Jr Varsity II
  • 85 replies
  • December 3, 2022

Hi @Naveen Boga,

I found that the event handling in extension library isn’t registered successfully.

I extended Graph in Visual Studio

Then upload the file .dll but somehow this handling isn’t applied

 

If I go with create event handler directly in Customization Project Editor, it works fine.

Do you have any idea why the event handling in .dll file didn’t work?


Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • 3393 replies
  • Answer
  • December 3, 2022

Hi @mrthanhkhoi  Please find the code here. I have verified it and it is working as expected.

 

public class ARDocumentResultExt : PXCacheExtension<ARDocumentResult>
    {
        #region UsrCustomerOrderNbr
        [PXString(50, IsUnicode = true)]
        [PXUIField(DisplayName = "Customer Order Nbr")]
        public virtual string UsrCustomerOrderNbr { get; set; }
        public abstract class usrCustomerOrderNbr : PX.Data.BQL.BqlString.Field<usrCustomerOrderNbr> { }
        #endregion
    }

    public class ARDocumentEnqExt : PXGraphExtension<ARDocumentEnq>
    {
        protected void ARDocumentResult_UsrCustomerOrderNbr_FieldSelecting(PXCache cache, PXFieldSelectingEventArgs e)
        {
            ARDocumentResult row = (ARDocumentResult)e.Row;
            if (row != null)
            {
                ARDocumentResultExt resext = row.GetExtension<ARDocumentResultExt>();
                ARInvoice invoiceObj = PXSelect<ARInvoice, Where<ARInvoice.docType, Equal<Required<ARInvoice.docType>>,
                                       And<ARInvoice.refNbr, Equal<Required<ARInvoice.refNbr>>>>>.Select(Base, row.DocType, row.RefNbr);
                if (invoiceObj != null)
                {
                    e.ReturnValue = invoiceObj.InvoiceNbr;
                }
            }
        }
    }

 

 

 


Forum|alt.badge.img
  • Author
  • Jr Varsity II
  • 85 replies
  • December 3, 2022

@Naveen Boga 

Thank you very much,

I found that I didn’t set property as CommitChanges =true for the field so it doesn’t work in my code

 

 


Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • 3393 replies
  • December 3, 2022

Ok Great. Thanks for the update @mrthanhkhoi 


Forum|alt.badge.img
  • Author
  • Jr Varsity II
  • 85 replies
  • December 4, 2022

Hi @Naveen Boga,

I do the same way to bring the field Customer->BillContact->FullName to Customer Details Screen with following code:

protected void ARDocumentResult_UsrAccountName_FieldSelecting(PXCache cache, PXFieldSelectingEventArgs e)
        {
            var row = (ARDocumentResult)e.Row;
            if (row == null)
            {
                return;
            }
            Customer customer = PXSelect<Customer,
                Where<Customer.bAccountID, Equal<Required<Customer.bAccountID>>>>.Select(Base, row.CustomerID);
            if (customer == null) { return; }
            Contact billContact = PXSelect<Contact,
                Where<Contact.contactID, Equal<Required<Contact.contactID>>>>.Select(Base, customer.DefBillContactID);
            if (billContact == null) { return; }
            e.ReturnValue = billContact.FullName;
        }

When I select the Customer for the first run, the result is correct as following: 

Note: Account Name is display name of UsrAccountName

However, if I select another Customer, the value of Account Name didn’t update (the value is from previous Customer)

Then I refresh the page, I got the correct one:

 

Somehow the event FieldSelecting is not affected immediately when I change the Customer.

Could you please advise me?


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