Skip to main content
Solved

Is there a way to access a Customers Primary Contact First Name from a Notification Template used for Shipment Confirmation?


Forum|alt.badge.img+1

We have a notification template set up which is fired by a business event when the status of a Shipment is set to confirmed.  This works fine but we want the email to the customer to have their first name rather than account name.  The Primary Contact first name is not exposed in the list of fields I can insert. I can see Primary Contact in the list but this seems to just be the numeric ID.

I tried adding a custom field to the shipments screen (SO302000) and set the visibility to false. This seemed to work and if I manually try to send an email with the source as the notification template the name appears.  If I try with the business event the first name in the email is blank. 

The field is defined as defined as a non-persisted text field and populated in the RowSelecting Event Handler:

public class SOShipmentEntry_Extension : PXGraphExtension<SOShipmentEntry>
{
    #region Event Handlers


    protected void SOShipment_RowSelecting(PXCache cache, PXRowSelectingEventArgs e, PXRowSelecting InvokeBaseHandler)
    {
      if(InvokeBaseHandler != null)
        InvokeBaseHandler(cache, e);
      var row = (SOShipment)e.Row;

      if (row == null) return;

      try {

        // Get the first name from the primary contact record

        SOShipmentExt soShipmentExt = row.GetExtension<SOShipmentExt>();

        Contact shipContact = PXSelectJoin<Contact,InnerJoin<Customer, On<Contact.contactID, Equal<Customer.primaryContactID>>, InnerJoin<SOOrderShipment,On<Customer.bAccountID, Equal<SOOrderShipment.customerID>>>>, Where<SOOrderShipment.shipmentNbr, Equal<Required<SOOrderShipment.shipmentNbr>>>>.Select(Base, row.ShipmentNbr);

        soShipmentExt.UsrPriContactFirstName = shipContact.FirstName;

      } catch(Exception error) {
        PXTrace.WriteInformation("Error is " + error);
      }
    }
}

Is there a different method I need to use to expose this information to the notification template or do I need to do something else so it can show up in the email fired by the business event?

Thanks for any advice/help,

Phil

Best answer by ppowell

I discovered that changing the field to a DB field gives me the functionality I needed.  I just changed the field type and used similar code in the RowSelecting event handler:

protected void SOShipment_RowSelecting(PXCache cache, PXRowSelectingEventArgs e, PXRowSelecting InvokeBaseHandler)
    {
      if(InvokeBaseHandler != null)
        InvokeBaseHandler(cache, e);
      var row = (SOShipment)e.Row;

      if (row == null) return;

      try {
        SOShipmentExt soShipmentExt = row.GetExtension<SOShipmentExt>();

        // Get the first name from the primary contact record

        Contact shipContact = PXSelectJoin<Contact,
                                            InnerJoin<Customer,
                                              On<Contact.contactID, Equal<Customer.primaryContactID>>
                                            >,
                                            Where<Customer.bAccountID, Equal<Required<Customer.bAccountID>>
                                            >
                                          >.Select(Base, row.CustomerID);

        if (shipContact != null) {
          soShipmentExt.UsrPriContactFirstName = shipContact.FirstName;
        }

      } catch(Exception error) {
        PXTrace.WriteInformation(error);
      }
    }

 

Thanks,

 

Phil

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

4 replies

DConcannon
Varsity II
Forum|alt.badge.img+2
  • Varsity II
  • 120 replies
  • July 29, 2022

@ppowell Try using ((DefaultCompanyContact.BAccountID.DefContactID.DisplayName)) in the email notification.


Forum|alt.badge.img+1
  • Author
  • Semi-Pro I
  • 134 replies
  • July 30, 2022

@DConcannon Thanks but that returns nothing for me.  Isn’t DefaultCompanyContact for our own company contact details?  We are using ((DefaultCompanyContact.EMail)) and ((DefaultCompanyContact.FullName)) to insert our own email address and contact details already in this notification. Or am I misunderstanding something?

 

Thanks,

 

Phil


Forum|alt.badge.img+1
  • Author
  • Semi-Pro I
  • 134 replies
  • Answer
  • August 3, 2022

I discovered that changing the field to a DB field gives me the functionality I needed.  I just changed the field type and used similar code in the RowSelecting event handler:

protected void SOShipment_RowSelecting(PXCache cache, PXRowSelectingEventArgs e, PXRowSelecting InvokeBaseHandler)
    {
      if(InvokeBaseHandler != null)
        InvokeBaseHandler(cache, e);
      var row = (SOShipment)e.Row;

      if (row == null) return;

      try {
        SOShipmentExt soShipmentExt = row.GetExtension<SOShipmentExt>();

        // Get the first name from the primary contact record

        Contact shipContact = PXSelectJoin<Contact,
                                            InnerJoin<Customer,
                                              On<Contact.contactID, Equal<Customer.primaryContactID>>
                                            >,
                                            Where<Customer.bAccountID, Equal<Required<Customer.bAccountID>>
                                            >
                                          >.Select(Base, row.CustomerID);

        if (shipContact != null) {
          soShipmentExt.UsrPriContactFirstName = shipContact.FirstName;
        }

      } catch(Exception error) {
        PXTrace.WriteInformation(error);
      }
    }

 

Thanks,

 

Phil


DConcannon
Varsity II
Forum|alt.badge.img+2
  • Varsity II
  • 120 replies
  • August 3, 2022

@ppowell  Thanks for the update on your solution! 

 

You’re right on the DefaultCompanyContact - I honed in on the BAccountID portion and did not take time to try my suggestion.


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