Skip to main content

Hi Team,

We have a requirement (Build 22.106.0015) where we want to change To Mail address for Email Invoice/Send Invoice actions to a generic email address, more specifically the To Mail address should use Customer Parent Account mail ID if configured but if not configured then should use the Customer mail ID.

 

And this functionality we wanted to have for Invoices, Invoices and Memos and Process Invoices and Memos screens.

 

Can you please let us know the best possible way to achieve this.

Thank you!

You can create a specific contact and then on the Mailing and Printing Tab select that contact. First select the invoice document and then on the bottom portion select Contact.

 


Hi @marina25,

Thank you for the inputs, will verify with the suggested setup and share the feedback. 

 


In order to get your initial if / then, I believe you’d need to extend or override the Email action (code customization) to check if there is a parent account and email it instead in that situation.

If you are satisfied doing that check manually, @marina25’s suggestion would work.

The downside to this, which I believe you understand, is that if the contact was configured to receive mail and the parent account was removed, the configured contact would continue to receive the emails until it was disabled.


Hi @darylbowman,

I tried with that override but after override did not find any info related to Customer (so that we can identify Parent account) or any other parameter that help us to pass required email ID. If you have any more information on that can you please share with us. Please find below sample for reference:

public class SOInvoiceEntry_Extension : PXGraphExtension<PX.Objects.SO.SOInvoiceEntry>
    {
        public static bool IsActive() { return true; }

        #region Event Handlers
       
        public delegate IEnumerable EmailInvoiceDelegate(PXAdapter adapter, String notificationCD);
        oPXOverride]
        public IEnumerable EmailInvoice(PXAdapter adapter, String notificationCD, EmailInvoiceDelegate baseMethod)
        {
            return baseMethod(adapter, notificationCD);
        }

        #endregion
    }


Maybe create a required contact field for parent contact email and add it to the mailing and printing tab. Then you can establish a process for which the system looks for parentBAccount id in the customer billing tab with value and will utilize the Parent Contac email field only if the value is not null for ParentBAccount.

 


I wrote this in a hurry, and didn’t test it whatsoever.

 

public delegate IEnumerable EmailInvoiceDelegate(PXAdapter adapter, String notificationCD);
PXOverride]
public IEnumerable EmailInvoice(PXAdapter adapter, String notificationCD, EmailInvoiceDelegate baseMethod)
{
var invoice = Base.Document.Current;
if (invoice is null)
return adapter.Get();

var customer = ARInvoice.FK.Customer.FindParent(new PXGraph(), invoice);
if (customer.ParentBAccountID is object)
{
// Email parent
return adapter.Get();
}
else
return baseMethod(adapter, notificationCD);
}

 


Hi @marina25 Thank you for the inputs, we verified the suggested approach and it worked as expected but it will be manual operation and we have to perform this for each and every customer and that would be time taking activity and is the reason we want to automate the process by overriding the individual Mail actions and the Processing screen.

@darylbowman Thank you for the inputs and sample code, I have implemented and tried with the same and able to get the parent email ID in below highlighted code piece.

public class ARInvoiceEntry_Extension : PXGraphExtension<PX.Objects.AR.ARInvoiceEntry>
    {
        public static bool IsActive() { return true; }

        #region Event Handlers
        public delegate IEnumerable SendEmailDelegate(PXAdapter adapter);
        ePXOverride]
        public IEnumerable SendEmail(PXAdapter adapter, SendEmailDelegate baseMethod)
        {
            var invoice = Base.Document.Current;
            if (invoice is null)
                return adapter.Get();

            var customer = ARInvoice.FK.Customer.FindParent(Base, invoice);
            if (customer?.ParentBAccountID is object)
            {
                // Email parent
                Contact contact = PXSelectJoin<Contact, InnerJoin<BAccount, On<BAccount.defContactID, Equal<Contact.contactID>, And<BAccount.bAccountID, Equal<Contact.bAccountID>>>>,
                                                    Where<Contact.bAccountID, Equal<Required<Contact.bAccountID>>>>.Select(Base, customer.ParentBAccountID);

                string pareEmailID = contact.EMail;
                return Base.Actions>"NewMailActivity"].Press(adapter);
            }
            else
                return baseMethod(adapter);
        }     
        #endregion
    }

 

But did not find any object where we can pass the parent mail ID, so that it will be further taken into consideration by system for further operation. As in below pop-up in ‘To’ field still the current Customer mail ID is loading by default.

 

Can you please review and suggest what I am messing here.


Hi @vivekm  were you able to find a solution? Thank you!


Hi @Chris Hackett,

Yes, I created a support case and received an alternate approach to achieve it through notification template.

Thank you!

 


Reply