How to Redirect to a Dashboard and pass parameter value - acumatica

Is it possible to redirect to a Dashboard Screen and pass dashboard parameter value on Acumatica? For example, the Customer View Dashboard on Acumatica has a parameter (see below) I would like to redirect to this screen with param value.

In order to redirect to Dashboard screen with param values, you can use the graph of the Dashboard(s) screen and pass the parameters to the Filter Dataview of the graph.
Then you can throw a PXRedirectRequiredException with Url, and graph(dashboard).
See snippet below:
public class CustomerMaint_Extension : PXGraphExtension<CustomerMaint>
{
#region Event Handlers
public PXAction<PX.Objects.AR.Customer> Test;
[PXButton(CommitChanges = true)]
[PXUIField(DisplayName = "test")]
protected void test()
{
Customer customer = Base.BAccount.Current;
if (customer != null)
{
string screenID = "DB000031";
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
}
See below:
Redirect with Parameter:

Related

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

Hiding custom fields in copy past option

How to hide a field while copy and past. The field is part of the extension of the sales order.DAC.
I have tried [PXCopyPasteHiddenFields(typeof(PSSOOrderExtNV.usrIsInHandsDate))] and I am getting the following compilation error.
Error CS0592 Attribute 'PXCopyPasteHiddenFields' is not valid on this declaration type. It is only valid on 'class, field' declarations.
I have tried to Override the method CopyPasteGetScript I did not get the desired result.
public delegate void CopyPasteGetScriptDelegate(Boolean isImportSimple, List<Command> script, List<Container> containers);
[PXOverride]
public void CopyPasteGetScript(Boolean isImportSimple, List<Command> script, List<Container> containers, CopyPasteGetScriptDelegate baseMethod)
{
baseMethod(isImportSimple, script, containers);
SOOrder order = Base.Document.Current;
if(Base.Document.Cache.GetStatus(order) == PXEntryStatus.Inserted)
{
PSSOOrderExtNV extn = PXCache<SOOrder>.GetExtension<PSSOOrderExtNV>(order);
extn.UsrHoldUntil = null;
extn.UsrReadyforProductionapproval = null;
extn.UsrReadyForProduction = null;
extn.UsrIsOrdered = null;
extn.UsrIsAllocated = null;
extn.UsrEmbPaperReceived = null;
extn.UsrEmbGoodsReceived = null;
extn.UsrWorksheetPrinted = null;
extn.UsrGoodsOnCarts = null;
Base.Document.Update(order);
}
}
Update
I have modified the code as bellow in graph extension of SOOrderEntry. It is not giving error while compiling, but it is copying the values to new order.
[PXCopyPasteHiddenFields(typeof(SOOrder.cancelled), typeof(SOOrder.preAuthTranNumber), typeof(SOOrder.ownerID), typeof(SOOrder.workgroupID),
typeof(PSSOOrderExtNV.usrHoldUntil),typeof(PSSOOrderExtNV.usrReadyForProduction),typeof(PSSOOrderExtNV.usrReadyforProductionapproval),typeof(PSSOOrderExtNV.usrIsOrdered),
typeof(PSSOOrderExtNV.usrIsAllocated),typeof(PSSOOrderExtNV.usrEmbPaperReceived),typeof(PSSOOrderExtNV.usrEmbGoodsReceived),typeof(PSSOOrderExtNV.usrWorksheetPrinted),
typeof(PSSOOrderExtNV.usrGoodsOnCarts))]
public PXSelect<SOOrder, Where<SOOrder.orderType, Equal<Current<SOOrder.orderType>>, And<SOOrder.orderNbr, Equal<Current<SOOrder.orderNbr>>>>> CurrentDocument;
PXCopyPasteHiddenFields attribute typically decorates DataViews.
This example in Sales Order graph, hides the SOLine.Completed field from the Transactions DataView:
[PXViewName(Messages.SOLine)]
[PXImport(typeof(SOOrder))]
[PXCopyPasteHiddenFields(typeof(SOLine.completed))]
public PXOrderedSelect<SOOrder, SOLine,
Where<SOLine.orderType, Equal<Current<SOOrder.orderType>>,
And<SOLine.orderNbr, Equal<Current<SOOrder.orderNbr>>>>,
OrderBy<Asc<SOLine.orderType, Asc<SOLine.orderNbr, Asc<SOLine.sortOrder, Asc<SOLine.lineNbr>>>>>> Transactions;

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

Custom Print Invoice Action on Process Screen

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:

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