Skip to content

Instantly share code, notes, and snippets.

@lekker-solutions
Created October 8, 2021 15:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lekker-solutions/10db36e695f0944886fb56daf91a1c3e to your computer and use it in GitHub Desktop.
Save lekker-solutions/10db36e695f0944886fb56daf91a1c3e to your computer and use it in GitHub Desktop.
Acumatica base Email code
public PXAction<SOOrder> emailSalesOrder;
[PXButton(CommitChanges = true), PXUIField(DisplayName = "Email Sales Order", MapEnableRights = PXCacheRights.Select)]
public virtual IEnumerable EmailSalesOrder(
PXAdapter adapter,
[PXString] string notificationCD = null) => Notification(adapter, notificationCD ?? "SALES ORDER");
public PXAction<SOOrder> emailQuote;
[PXButton(CommitChanges = true), PXUIField(DisplayName = "Email Quote", MapEnableRights = PXCacheRights.Select)]
public virtual IEnumerable EmailQuote(
PXAdapter adapter,
[PXString] string notificationCD = null) => Notification(adapter, notificationCD ?? "QUOTE");
public PXAction<SOOrder> notification;
[PXUIField(DisplayName = "Notifications", Visible = false)]
[PXButton(ImageKey = PX.Web.UI.Sprite.Main.DataEntryF)]
protected virtual IEnumerable Notification(PXAdapter adapter, [PXString] string notificationCD)
{
bool massProcess = adapter.MassProcess;
var orders = adapter.Get<SOOrder>().ToArray();
PXLongOperation.StartOperation(this, () =>
{
var soEntry = Lazy.By(() => PXGraph.CreateInstance<SOOrderEntry>());
bool anyfailed = false;
foreach (SOOrder order in orders)
{
if (massProcess) PXProcessing<SOOrder>.SetCurrentItem(order);
try
{
var parameters = new Dictionary<string, string>
{
[nameof(SOOrder) + "." + nameof(SOOrder.OrderType)] = order.OrderType,
[nameof(SOOrder) + "." + nameof(SOOrder.OrderNbr)] = order.OrderNbr,
};
soEntry.Value.Document.Current = order;
soEntry.Value.Activity.SendNotification(ARNotificationSource.Customer, notificationCD, order.BranchID, parameters);
soEntry.Value.Document.Update(order); // to apply field assignments made to an order
if (massProcess) PXProcessing<SOOrder>.SetProcessed();
}
catch (Exception exception) when (massProcess)
{
PXProcessing<SOOrder>.SetError(exception);
anyfailed = true;
}
}
if (soEntry.Value.Document.Cache.IsDirty)
soEntry.Value.Save.Press();
if (anyfailed)
throw new PXOperationCompletedWithErrorException(ErrorMessages.SeveralItemsFailed);
});
return orders;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment