Creating a new processing button that sends emails
Hi,
I am creating a new processing screen that will be used to send invoice reminders to customers, but I am not sure how to set up the send email button to do this correctly.
Below is an example of how I was trying to set it up. This code doesn’t publish because of some errors, so I know it’s completely wrong, but I am not sure how I can correct it.
protected IEnumerable SendEmail(PXAdapter adapter) { // Loop through all selected rows to process foreach (DunningLettersDAC currentRecord in Base.ProcessingScreen.Cache.Updated) { var emailSettings = new SendMailSettings { Subject = "Your Email Subject", Body = "Your Email Body", AppendFiles = true };
sendEmail.PressButton(adapter, emailSettings); }
return adapter.Get(); }
Here is a list of what i am expecting this button to do, so let me know if there are some things on this list that on this list I won’t be able to achieve:
Send email button should pull information from an existing email template
To determine the email to send an email to, it should grab the Customer ID from the row currently being processed and pull the email from the customer card
If possible, it should attach the relevant Customer Statement to the email, which I guess would be handled via the Email Template if it can be grabbed via the code for this new button.
What is the best way to trigger an email from from a custom button in a processing screen?
Let me know if you need any other information about what I am trying to do.
protected virtual IEnumerable Notification(PXAdapter adapter, PXString] string notificationCD) { var records = adapter.Get<YourDAC>().ToArray();
PXLongOperation.StartOperation(this, () => { var recEntry = Lazy.By(() => PXGraph.CreateInstance<YourGraph>());
foreach (YourDAC dac in records) { try { recEntry.Value.Clear();
using (var ts = new PXTransactionScope()) { var parameters = new Dictionary<string, string> { nameof(DAC) + "." + nameof(Field)] = value, nameof(DAC) + "." + nameof(Field)] = value, };
recEntry.Value.Document.Current = dac; recEntry.Value.Activity.SendNotification(ARNotificationSource.Customer, notificationCD, order.BranchID, parameters); recEntry.Value.Document.Update(dac); // to apply field assignments made to an record
Thanks for your sending through that code. I filled in the places I believe I needed to change, and I have received some errors below when trying to publish these changes. I have also included the code I updated below the errors so you can see if I have updated something incorrectly that is causing an issue.
Do you know how to resolve some of these issues?
Also, in your code, I can see you are using a PXTransactionScope. Could you please explain what bit of code is doing as I was not sure how I needed to set it up.
Let me know if you need any other information.
Kind regards,
Andrew
\App_Code\Caches\DunningLettersGraph.cs(44): error CS1061: 'IEnumerable<DunningLettersDAC>' does not contain a definition for 'ToArray' and no accessible extension method 'ToArray' accepting a first argument of type 'IEnumerable<DunningLettersDAC>' could be found (are you missing a using directive or an assembly reference?)
\App_Code\Caches\DunningLettersGraph.cs(48): error CS0305: Using the generic type 'Lazy<T>' requires 1 type arguments
\App_Code\Caches\DunningLettersGraph.cs(50): error CS1579: foreach statement cannot operate on variables of type '?' because '?' does not contain a public instance definition for 'GetEnumerator'
\App_Code\Caches\DunningLettersGraph.cs(58): error CS0246: The type or namespace name 'Dictionary<,>' could not be found (are you missing a using directive or an assembly reference?)
\App_Code\Caches\DunningLettersGraph.cs(60): error CS0103: The name 'value' does not exist in the current context
\App_Code\Caches\DunningLettersGraph.cs(61): error CS0103: The name 'value' does not exist in the current context
\App_Code\Caches\DunningLettersGraph.cs(65): error CS0103: The name 'order' does not exist in the current context
\App_Code\Caches\DunningLettersGraph.cs(78): error CS0103: The name 'Base' does not exist in the current context
\App_Code\Caches\DunningLettersGraph.cs(44): error CS1061: 'IEnumerable<DunningLettersDAC>' does not contain a definition for 'ToArray' and no accessible extension method 'ToArray' accepting a first argument of type 'IEnumerable<DunningLettersDAC>' could be found (are you missing a using directive or an assembly reference?)
protected virtual IEnumerable Notification(PXAdapter adapter, rPXString] string notificationCD) { var records = adapter.Get<DunningLettersDAC>().ToArray();
PXLongOperation.StartOperation(this, () => { var recEntry = Lazy.By(() => PXGraph.CreateInstance<DunningLettersGraph>());
foreach (DunningLettersDAC dac in records) { try { recEntry.Value.Clear();
using (var ts = new PXTransactionScope()) { var parameters = new Dictionary<string, string> { nameof(dac) + "." + nameof(dac.CustomerID)] = value, nameof(dac) + "." + nameof(dac.CustomerID_description)] = value, };
recEntry.Value.Document.Current = dac; recEntry.Value.Activity.SendNotification(ARNotificationSource.Customer, notificationCD, order.BranchID, parameters); recEntry.Value.Document.Update(dac); // to apply field assignments made to an record
@AndrewA Acumatica has a dedicated processing page for sending out Dunning Letter notifications, is there a problem with that? Why would you develop a new, separate page doing pretty much the same thing?
Hi @Samvel Petrosov ,
The client is currently on a licensing level that doesn’t provide this feature, and they are not wanting to upgrade licenses just for a single feature. Therefore, we are being tasked with recreating this for them so they can use this process in their current system.
Kind regards,
Andrew
Hi @KumarDighe ,
Thanks for your sending through that code. I filled in the places I believe I needed to change, and I have received some errors below when trying to publish these changes. I have also included the code I updated below the errors so you can see if I have updated something incorrectly that is causing an issue.
Do you know how to resolve some of these issues?
Also, in your code, I can see you are using a PXTransactionScope. Could you please explain what bit of code is doing as I was not sure how I needed to set it up.
Let me know if you need any other information.
Kind regards,
Andrew
\App_Code\Caches\DunningLettersGraph.cs(44): error CS1061: 'IEnumerable<DunningLettersDAC>' does not contain a definition for 'ToArray' and no accessible extension method 'ToArray' accepting a first argument of type 'IEnumerable<DunningLettersDAC>' could be found (are you missing a using directive or an assembly reference?)
\App_Code\Caches\DunningLettersGraph.cs(48): error CS0305: Using the generic type 'Lazy<T>' requires 1 type arguments
\App_Code\Caches\DunningLettersGraph.cs(50): error CS1579: foreach statement cannot operate on variables of type '?' because '?' does not contain a public instance definition for 'GetEnumerator'
\App_Code\Caches\DunningLettersGraph.cs(58): error CS0246: The type or namespace name 'Dictionary<,>' could not be found (are you missing a using directive or an assembly reference?)
\App_Code\Caches\DunningLettersGraph.cs(60): error CS0103: The name 'value' does not exist in the current context
\App_Code\Caches\DunningLettersGraph.cs(61): error CS0103: The name 'value' does not exist in the current context
\App_Code\Caches\DunningLettersGraph.cs(65): error CS0103: The name 'order' does not exist in the current context
\App_Code\Caches\DunningLettersGraph.cs(78): error CS0103: The name 'Base' does not exist in the current context
\App_Code\Caches\DunningLettersGraph.cs(44): error CS1061: 'IEnumerable<DunningLettersDAC>' does not contain a definition for 'ToArray' and no accessible extension method 'ToArray' accepting a first argument of type 'IEnumerable<DunningLettersDAC>' could be found (are you missing a using directive or an assembly reference?)
protected virtual IEnumerable Notification(PXAdapter adapter, ePXString] string notificationCD) { var records = adapter.Get<DunningLettersDAC>().ToArray();
PXLongOperation.StartOperation(this, () => { var recEntry = Lazy.By(() => PXGraph.CreateInstance<DunningLettersGraph>());
foreach (DunningLettersDAC dac in records) { try { recEntry.Value.Clear();
using (var ts = new PXTransactionScope()) { var parameters = new Dictionary<string, string> { nameof(dac) + "." + nameof(dac.CustomerID)] = value, nameof(dac) + "." + nameof(dac.CustomerID_description)] = value, };
recEntry.Value.Document.Current = dac; recEntry.Value.Activity.SendNotification(ARNotificationSource.Customer, notificationCD, order.BranchID, parameters); recEntry.Value.Document.Update(dac); // to apply field assignments made to an record
protected virtual IEnumerable Notification(PXAdapter adapter, rPXString] string notificationCD) { var records = adapter.Get<DunningLettersDAC>().ToArray();
PXLongOperation.StartOperation(this, () => { var recEntry = Lazy.By(() => PXGraph.CreateInstance<DunningLettersGraph>());
foreach (DunningLettersDAC dac in records) { try { recEntry.Value.Clear();
using (var ts = new PXTransactionScope()) { var parameters = new Dictionary<string, string> { nameof(dac) + "." + nameof(dac.CustomerID)] = value, nameof(dac) + "." + nameof(dac.CustomerID_description)] = value, };
recEntry.Value.Document.Current = dac; recEntry.Value.Activity.SendNotification(ARNotificationSource.Customer, notificationCD, order.BranchID, parameters); recEntry.Value.Document.Update(dac); // to apply field assignments made to a record