Solved

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

  • 29 July 2022
  • 4 replies
  • 165 views

Userlevel 5
Badge +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

icon

Best answer by ppowell 3 August 2022, 16:28

View original

4 replies

Userlevel 6
Badge +2

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

Userlevel 5
Badge +1

@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

Userlevel 5
Badge +1

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

Userlevel 6
Badge +2

@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.

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved