0
votes

I have created an extension for ARInvoiceEntry with a custom action that replicates SendARInvoiceMemo but adds an additional attachment to the invoice notification email.

This works as expected with an extra button, but I need it to replace the original action. I have used the same name for it to overload the existing one but it doesn't seem to work.

How can I force Acumatica to use my action in the GraphExtension instead of the original?

Here is my extended action code:

public PXAction<ARInvoice> sendARInvoiceMemo;

[PXUIField(DisplayName = "+Send AR Invoice/Memo+", MapEnableRights = PXCacheRights.Select, MapViewRights = PXCacheRights.Select)]
[PXLookupButton]
public virtual IEnumerable SendARInvoiceMemo(PXAdapter adapter,
    [PXString]
    string reportID)
{
    var cfdi = ARInvoiceXmlDownload.GetXmlAttachment(this.Base, this.Base.Document.Current);

    if (cfdi == null)
    {
        return Base.SendARInvoiceMemo(adapter, reportID);
    }

    ARInvoice invoice = this.Base.Document.Current;
    if (reportID == null) reportID = "AR641000";
    if (invoice != null)
    {
        Dictionary<string, string> mailParams = new Dictionary<string, string>();
        mailParams["DocType"] = invoice.DocType;
        mailParams["RefNbr"] = invoice.RefNbr;

        var sent = false;
        var activities = PX.Objects.EP.ReportNotificationGenerator.Send(reportID, mailParams);
        var updatedActivities = new List<EPActivity>();
        foreach (var act in activities)
        {
            AddCfdi(act, cfdi.UID);
            sent = true;
        }

        if (sent)
        {
            this.Base.Caches<NoteDoc>().Persist(PXDBOperation.Insert);
        }
        else
        {
            throw new PXException(ErrorMessages.MailSendFailed);
        }

        this.Base.Clear();
        this.Base.Document.Current = this.Base.Document.Search<ARInvoice.refNbr>(invoice.RefNbr, invoice.DocType);
    }
    return adapter.Get();
}

Edit for clarification as requested

This is for Acumatica v5.30.2741

This is the action in Invoices and Memos (AR301000) I need to replace: This is the action in Invoices and Memos (AR301000) I need to replace

It is also used in Print Invoices and Memos (AR508000) to send several invoices in a process: It is also used in Print Invoices and Memos (AR508000) to send several invoices in a process

1

1 Answers

2
votes

With the extensibility framework, an action from base BLC is always completely replaced by the identically-named action declared within a BLC extension. For more information about how to modify actions with the Acumatica Extensibility Framework, check BLC Extension Model article in Help -> Customization.

To modify Email Invoice/Memo button, in the ARInvoiceEntry BLC extension you should customize notification action:

public PXAction<ARInvoice> notification;
[PXUIField(DisplayName = "Notifications", Visible = false)]
[PXButton(ImageKey = PX.Web.UI.Sprite.Main.DataEntryF)]
protected virtual IEnumerable Notification(PXAdapter adapter,
    [PXString]
    string notificationCD)
{
    foreach (ARInvoice doc in adapter.Get())
    {
        Dictionary<string, string> parameters = new Dictionary<string, string>();
        parameters.Add("DocType", doc.DocType);
        parameters.Add("RefNbr", doc.RefNbr);

        using (var ts = new PXTransactionScope())
        {
            Base.Activity.SendNotification(ARNotificationSource.Customer, notificationCD, doc.BranchID, parameters);
            Base.Save.Press();

            ts.Complete();
        }

        yield return doc;
    }
}

In this particular scenario, the proper way to determine what action to customize is by exploring automation steps set up for the Invoices and Memos screen (AR301000) as shown on 2 screenshots below:

enter image description here

enter image description here

Speaking about the sendARInvoiceMemo action, it looks like a leftover not used on the Invoices and Memos screen (AR301000) anymore. Though it's still used in Automation Steps for the Cash Sales screen (AR304000) as shown on the screenshot below: enter image description here