Custom Print Invoice Action on Process Screen - acumatica

I am trying to have a print invoice Action on my new process screen which points to new custom report taking Customer Ref Nbr as a parameter. Any help on how to start with this?

In Acumatica redirection to another page (points to new custom report) is done by throwing redirection exceptions. For redirecting to a report page the exception you should use is 'PXReportRequiredException'.
Code for launching your custom report with parameter:
public PXAction<Customer> printInvoice;
[PXUIField(DisplayName = "Print Invoice", MapEnableRights = PXCacheRights.Select, MapViewRights = PXCacheRights.Select)]
public virtual IEnumerable PrintInvoice(PXAdapter adapter)
{
Customer customer = [fetch desired customer record here];
if (customer != null && customer.RefNbr != null)
{
// Add your report parameters to a Dictionary<string, string> collection.
// The dictionary key is the parameter name as shown in the report editor.
// The dictionary value is the value you assign to that parameter.
Dictionary<string, string> parameters = new Dictionary<string, string>();
parameters["RefNbr"] = customer.RefNbr;
// Provide your custom report ReportID
string reportID = "AR641000";
// Provide a title name for your report page
string reportName = "Customer Invoice"
// Redirect to report page by throwing a PXReportRequiredException object
throw new PXReportRequiredException(parameters, reportID, reportName);
}
return adapter.Get();
}
You can look up the parameter names in the Parameters tab of the Schema Builder dialog of Acumatica Report Designer:

Related

Acumatica - Copy custom field contents from SO to IN

I have a similar type of issue as in
Acumatica refer custom field to another custom field on different screen
except that I am using custom source fields.
I created and added 2 fields to the SO Line to capture EDI data needed for invoicing. I created 2 new fields on the invoice line with the same name (different data class of course) on the SO Invoice form. Below is the code for 1 field on each of the forms:
SO301000 (Sales Orders):
[PXDBString(3)]
[PXUIField(DisplayName="Cust.Invoice Line Nbr.")]
[PXFormula(typeof(Selector<SOLineExt.usrCInvLine, ARTranExt.usrCInvLine>))]
SO303000 (Invoices):
[PXDBString(3)]
[PXUIField(DisplayName="Cust.Invoice Line Nbr.")]
It compiles but the data is not being copied to the invoice when created from shipment. I also added 1 of the fields to the shipment form for testing purposes but it does nit capture that value either.
Do I have this backwards?
After reviewing it into more details, you could override the Prepare Invoice method on SOOrderEntry graph (and also anywhere else is needed).
By overriding the PrepareInvoice Method of SOOrderEntry graph you could add a Handler(RowInserting) to SOInvoiceEntry graph to populate your new Custom field with the value on SOOrder.
See sample below where I'm doing similar action copying value from SOOrder(Header) to ARTran(details).
You can use this sample to achieve your goal: (In your case you could use ARInvoice instead of ARTran)
SOOrderEntry:
public class SOOrderEntry_Extension:PXGraphExtension<SOOrderEntry>
{
public PXAction<SOOrder> prepareInvoice;
[PXUIField(DisplayName = "Prepare Invoice", MapEnableRights = PXCacheRights.Select, MapViewRights = PXCacheRights.Select, Visible = false)]
[PXButton]
public virtual IEnumerable PrepareInvoice(PXAdapter adapter)
{
PXGraph.InstanceCreated.AddHandler<SOInvoiceEntry>((graph) =>
{
graph.RowInserting.AddHandler<ARTran>((sender, e) =>
{
//Custom logic goes here
var row = (ARTran)e.Row;
if (row == null)
return;
SOOrder order = Base.Document.Current;
if (order != null)
{
var tranExt = PXCache<ARTran>.GetExtension<ARTranExt>(row);
//Below to be change to your needs
//Here you can look for the SOLine of the SOOrder instead
var orderExt = PXCache<SOOrder>.GetExtension<SOOrderExt>(order);
if (orderExt != null && tranExt != null)
{
tranExt.UsrContactID = orderExt.UsrContactID;
}
//END
}
});
});
return Base.prepareInvoice.Press(adapter);
}
}
You could also find more information and instructions provided by my colleague on the stackoverflow link below:
Acumatica custom field SOLine transferred to ARTran

How do I redirect to a dashboard now that GIScreenHelper is marked obsolete?

We have a dashboard that is accessed via the Inquiry menu on the Stocked Items page. Until our most recent minor upgrade on 2019 R2, the following code compiled without issue to allow opening the dashboard relevant to the current Inventory ID. It still compiles but with a warning that GIScreenHelper is obsolete and will be marked internal in the next upgrade. Hence my question... how do I redirect to a dashboard if I can't use GIScreenHelper to initialize the graph used in the PXRedirectRequiredException?
string screenID = "SS0010DB"; //DashboardID
PXSiteMapNode sm = GIScreenHelper.GetSiteMapNode(screenID);
PXGraph graph = GIScreenHelper.InstantiateGraph(screenID);
if (graph is LayoutMaint)
{
LayoutMaint copygraph = graph as LayoutMaint;
Dictionary<string, object> parameters = new Dictionary<string, object>();
parameters["InventoryID"] = item.InventoryCD;
copygraph.Filter.Current.Values = parameters;
throw new PXRedirectRequiredException(sm.Url, copygraph, PXBaseRedirectException.WindowMode.New, string.Empty);
}
I have tried initializing LayoutMaint directly, but I can't figure out what to set to specify which Screen ID to utilize and pass parameters.
I guess you have 2 options here:
Create the DashboardMaint graph instance which is the Dashboards page graph and provide the Name of the Dashboard and invoke the viewDashboard action of that graph.
Just take the code of the viewDashboard action of the DashboardMaint and redirect to your Dashboard directly:
[PXButton(ConfirmationType = PXConfirmationType.IfDirty, ConfirmationMessage = "Any unsaved changes will be discarded. Do you want to proceed?")]
[PXUIField(DisplayName = "View")]
public void viewDashboard()
{
throw new PXRedirectToUrlException(PXSiteMap.Provider.FindSiteMapNodeByScreenID(this.Dashboards.Current.ScreenID).Url, PXBaseRedirectException.WindowMode.Same, "View Dashboard");
}
UPDATED
Below is a code example how to open Dashboard with predefined value for Filter.
The example is written for Customer View dashboard.
[PXButton(CommitChanges = true)]
[PXUIField(DisplayName = "CustomerView")]
protected virtual IEnumerable RedirectToCustomerViewDashboard(PXAdapter adapter)
{
string screenID = "DB000031"; //DashboardID
LayoutMaint graph;
using (new PXScreenIDScope(screenID))
{
graph = PXGraph.CreateInstance<LayoutMaint>(screenID);
}
Dictionary<string, object> parameters = new Dictionary<string, object>();
parameters["CustomerAccountID"] = "ABARTENDE";
graph.Filter.Current.Values = parameters;
throw new PXRedirectRequiredException(PXSiteMap.Provider.FindSiteMapNodeByScreenID(screenID).Url, graph, PXBaseRedirectException.WindowMode.New, string.Empty);
}
The key for the value is Name of the parameter from Dashboard definition

Acumatica Redirect to a Dashboard and pass parameter value issue

I'm successfully redirecting to a Dashboard passing parameter from Customers screen (AR303000) but, not able to replicate the result when I redirect to the Dashboard from Customer Pop Up Panel. it call the Dashboard without the parameter. I can see the code passing the value correctly, but the Dashboard does not display any value.
Any Help will be appreciated.
Thanks.
Alfredo
Here is a copy of the code.
#region CustomerCard
public PXAction<PX.Objects.AR.Customer> customerCard;
[PXButton(CommitChanges = true)]
[PXUIField(DisplayName = "Customer Card")]
protected void CustomerCard()
{
Customer customer = Base.BAccount.Current;
if (customer != null)
{
string screenID = "DBPS0007"; //DashboardID
PXSiteMapNode sm = GIScreenHelper.GetSiteMapNode(screenID);
PXGraph graph = GIScreenHelper.InstantiateGraph(screenID);
if (graph is LayoutMaint)
{
LayoutMaint copygraph = graph as LayoutMaint;
Dictionary<string, object> parameters = new
Dictionary<string, object>();
parameters["CustomerAccountID"] = customer.AcctCD;
copygraph.Filter.Current.Values = parameters;
throw new PXRedirectRequiredException(sm.Url, copygraph,
PXBaseRedirectException.WindowMode.New, string.Empty);
}
}
}
#endregion

Set Field Value during Email Sales Order process under Slaes Order Entry Actions

I created a new field, UsrAcknowledged, boolean, checkbox, and placed it on the SOLine details grid. I want every line on the details grid to be checked when the Email Sales Order/Quote process is run under Actions for SOOrder. My code is as follows under the SOOrderEntry_Extension:PXGraphExtension
public CRActivityList<SOOrder> Activity;
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
)
{
foreach (SOOrder order in adapter.Get<SOOrder>())
{
var parameters = new Dictionary<string, string>();
parameters["SOOrder.OrderType"] = order.OrderType;
parameters["SOOrder.OrderNbr"] = order.OrderNbr;
Activity.SendNotification(ARNotificationSource.Customer, notificationCD, order.BranchID, parameters);
//order.OrderDesc = "Desc";
foreach (SOLine line in PXSelect<SOLine>.Select(Base, order.OrderNbr))
{
SOLineExt rowExt = line.GetExtension<SOLineExt>();
rowExt.UsrAcknowledged = true;
line.OrderQty = 5;
}
yield return order;
}
}
//order.Desc = "Desc" was an initial simple test just to see if my code was achieving the desired results and the proder desciption was changed as planned.
My code compiles and the email process runs as planned with a green check for successful, but neither the Acknowledged check box nor the Order Quantity are changed. I don't really care about the ord qty, it was just another test.
Any suggestions for what I can change to update the Acknowledged checkbox to checked during the Email Sales Order/Quote under Actions on the SO Order Entry screen would be appreciated
I would say you need to call Base.Transactions.Update(line) after you update your row values inside your foreach.

Print button on CR306000 to print case data

I have a custom button on CR306000 to try to print current loaded case information by calling one customized report. Navigation URL current set to:
~/Frames/ReportLauncher.aspx?ID=Inquirycase.rpx&CASEID=####
I will need to have custom programming to assign current case ID to replace "####", but don't know where and how to reference that custom button and modify its property. Please help. Thanks.
You could add a report parameter called 'CaseID' to your report and call it using the following code using an AEF extension like this:
public class CRCaseMaintExtension : PXGraphExtension<CRCaseMaint>
{
public override void Initialize()
{
base.Initialize();
//if adding to an existing menu button do that here...
// Example:
//Base.Inquiry.AddMenuAction(this.CustomReportButton);
}
public PXAction<CRCase> CustomReportButton;
[PXButton]
[PXUIField(DisplayName = "Custom Report", MapEnableRights = PXCacheRights.Select, MapViewRights = PXCacheRights.Select)]
public virtual IEnumerable customReportButton(PXAdapter adapter)
{
if (Base.Case.Current != null)
{
Dictionary<string, string> parameters = new Dictionary<string, string>();
parameters["CaseID"] = Base.Case.Current.CaseID.ToString();
//enter in your report id/number here
string reportNumber = "Inquirycase";
//opens the report using the defined parameters
throw new PXReportRequiredException(parameters, reportNumber, "Custom Report");
}
return adapter.Get();
}
}
I have not tested the above but this should get you most of the way there.

Resources