Skip to main content
Answer

Copy UDF data from lead form to contact form automatically

  • July 28, 2021
  • 1 reply
  • 140 views

Forum|alt.badge.img

On the Lead profile screen (CR301000), I created a custom field to store a string values called UsrDepartment.  I also created the same field on the Contact profile screen (CR302000).  When the user chooses to “Create Contact” from the Lead profile, it correctly creates the contact.  However, the data in the custom field I created doesn’t automatically carry over.  How and where can I add logic to copy the value over from the lead to the contact?

Best answer by sd79

You can use the following code to achieve the same. I have created 2 fields Region and Industry to carry forward from Leads screen to Contact Screen.

 

namespace PX.Objects.CR
{
    

    public class ContactMaint_Extension : PXGraphExtension<ContactMaint>
    {
        #region Event Handlers
        protected void Contact_RowPersisted(PXCache cache, PXRowPersistedEventArgs e)
        {
            var row = (Contact)e.Row;
            if (row != null)
            {
                CRContactExistingColumn TargateExt = PXCache<Contact>.GetExtension<CRContactExistingColumn>(row);

                if (row.ContactID != null)
                {

                    CRLead lead = PXSelect<CRLead, Where<CRLead.refContactID, Equal<Required<CRLead.refContactID>>>>.Select(this.Base, row.ContactID);

                    if (lead != null)
                    {
                        Contact Source = PXSelect<Contact, Where<Contact.contactID, Equal<Required<Contact.contactID>>>>.Select(this.Base, lead.ContactID);
                        CRContactExistingColumn SourceExt = PXCache<Contact>.GetExtension<CRContactExistingColumn>(Source);
                        TargateExt.Usrregion = SourceExt.Usrregion;
                        TargateExt.Usrindustry = SourceExt.Usrindustry;
                    }
                }
            }
        }
        #endregion
    }
}
 

1 reply

Forum|alt.badge.img
  • Freshman II
  • Answer
  • December 29, 2022

You can use the following code to achieve the same. I have created 2 fields Region and Industry to carry forward from Leads screen to Contact Screen.

 

namespace PX.Objects.CR
{
    

    public class ContactMaint_Extension : PXGraphExtension<ContactMaint>
    {
        #region Event Handlers
        protected void Contact_RowPersisted(PXCache cache, PXRowPersistedEventArgs e)
        {
            var row = (Contact)e.Row;
            if (row != null)
            {
                CRContactExistingColumn TargateExt = PXCache<Contact>.GetExtension<CRContactExistingColumn>(row);

                if (row.ContactID != null)
                {

                    CRLead lead = PXSelect<CRLead, Where<CRLead.refContactID, Equal<Required<CRLead.refContactID>>>>.Select(this.Base, row.ContactID);

                    if (lead != null)
                    {
                        Contact Source = PXSelect<Contact, Where<Contact.contactID, Equal<Required<Contact.contactID>>>>.Select(this.Base, lead.ContactID);
                        CRContactExistingColumn SourceExt = PXCache<Contact>.GetExtension<CRContactExistingColumn>(Source);
                        TargateExt.Usrregion = SourceExt.Usrregion;
                        TargateExt.Usrindustry = SourceExt.Usrindustry;
                    }
                }
            }
        }
        #endregion
    }
}