Does anyone know how to add menu item of Report button in Bill & Adjusment Screen of Acumatica ERP System, please see the following screenshot.
And also I've created some customize code for new action button, please see the following code.
namespace PX.Objects.AP
{
public class APInvoiceEntry_Extension : PXGraphExtension<APInvoiceEntry>
{
public override void Initialize()
{
Base.report.AddMenuAction(VendorInvoiceUnreleased);
Base.report.AddMenuAction(VendorInvoiceReleased);
}
#region buton Vendor Invoice Not Released
public PXAction<APInvoice> VendorInvoiceUnreleased;
[PXButton]
[PXUIField(DisplayName = "Vendor Invoice")]
public IEnumerable vendorInvoiceUnreleased(PXAdapter adapter)
{
var result = adapter.Get<APInvoice>();
foreach (APInvoice doc in result)
{
object FinPeriodID;
if (Base.Caches[typeof(APInvoice)].GetStatus(doc) == PXEntryStatus.Notchanged)
{
Base.Caches[typeof(APInvoice)].SetStatus(doc, PXEntryStatus.Updated);
}
Base.Save.Press();
var docPeriod = (FinPeriodID = Base.Caches[typeof(APInvoice)].GetValueExt<APRegister.finPeriodID>(doc)) is PXFieldState ? (string)((PXFieldState)FinPeriodID).Value : (string)FinPeriodID;
Dictionary<string, string> parameters = new Dictionary<string, string>();
parameters["BranchID"] = null;
parameters["PeriodFrom"] = docPeriod;
parameters["PeriodTo"] = docPeriod;
parameters["CreatedBy"] = null;
parameters["LastModifiedBy"] = null;
parameters["DocType"] = doc.DocType;
parameters["RefNbr"] = doc.RefNbr;
throw new PXReportRequiredException(parameters, "AP910503", "Report");
}
return result;
}
#endregion
#region Vendor Invoice Released
public PXAction<APInvoice> VendorInvoiceReleased;
[PXButton]
[PXUIField(DisplayName = "Vendor Invoice Released")]
public IEnumerable vendorInvoiceReleased(PXAdapter adapter)
{
var result = adapter.Get<APInvoice>();
foreach (APInvoice doc in result)
{
object FinPeriodID;
if (Base.Caches[typeof(APInvoice)].GetStatus(doc) == PXEntryStatus.Notchanged)
{
Base.Caches[typeof(APInvoice)].SetStatus(doc, PXEntryStatus.Updated);
}
Base.Save.Press();
var docPeriod = (FinPeriodID = Base.Caches[typeof(APInvoice)].GetValueExt<APRegister.finPeriodID>(doc)) is PXFieldState ? (string)((PXFieldState)FinPeriodID).Value : (string)FinPeriodID;
Dictionary<string, string> parameters = new Dictionary<string, string>();
parameters["BranchID"] = null;
parameters["PeriodFrom"] = docPeriod;
parameters["PeriodTo"] = docPeriod;
parameters["CreatedBy"] = null;
parameters["LastModifiedBy"] = null;
parameters["DocType"] = doc.DocType;
parameters["RefNbr"] = doc.RefNbr;
throw new PXReportRequiredException(parameters, "AP910501", "Report");
}
return result;
}
#endregion
But, I've the following error.
This code is work if in Acumatica Version 2017 R2, but it doesn't in 2021 R1 version. Does anyone know the correct method to solve this issue ??
Thanks.
I would suggest to make use of the acumatica customization project feature. This is accessible from the customization project. For this approach you have two possible scenarios. If a button is only required to show a report only and no additional logic. In this case you can just specify the button in the actions section of the screen in the customization project as seen in the below screenshot.
The other option is to define the button in the code and then also go to the actions section of the customization project and instead of add new you can select add existing. This will add your existing button and you'll be able to specify that you want it to be under the reports menu.