Acumatica provides a very powerful tool that powers reports, dashboards, etc. The Generic Inquiry (GI) enables placing the power of data into the end user’s hands with the flexibility on the user side to lessen demands on IT for custom reports. Leveraging filters on a GI, they can be made contextual. Leveraging the ability to filter a GI to a specific item or vendor, for instance, creates a means to build a meaningful menu system to navigate a user to related data quickly and easily.
Just a few examples of commonly needed data include:
- Vendors of an Item
- Open Purchase Orders to a Supplier
- Unpaid Invoices from a Supplier
- Transactional Movement of an Inventory Item
This post will not get into creating the GI itself, but rather how to create a menu item to access the GI and leverage the filter ability to view the GI contextual to the Item, Vendor, etc. being viewed at the time.
To get started, let’s define a few variables within our Graph to simplify the code and help us change the behavior later if needed.
private bool CallGIbyScreen = true;
private string giURL = PXGenericInqGrph.INQUIRY_URL;
private string urlFormat = "{0}?Name={1}&{2}={3}";
Next, if we expect to have many menu items and would like to make a line to separate groups of menu items, define an action to place on the menu as seen below.
#region Menu Separator 1
public PXAction<InventoryItem> menuSeparator1;
[PXUIField(DisplayName = Blog.Messages.MenuBar,
Enabled = false, MapEnableRights = PXCacheRights.Select)]
[PXButton]
protected virtual IEnumerable MenuSeparator1(PXAdapter adapter)
{
return adapter.Get();
}
#endregion
Now let’s define an action for access to the GI. In this example, our Action is called TransactionsInq, and our GI is called BLOG-Transactions with a Screen ID of BLOG01GI. We will access the GI through the Parameter (filter) called InventoryID, passing the InventoryCD value (the human readable Inventory ID).
#region Transactions Inquiry Menu
public PXAction<InventoryItem> transactionsInq;
[PXUIField(DisplayName = "Transactions",
MapEnableRights = PXCacheRights.Select)]
[PXButton]
protected virtual IEnumerable TransactionsInq(PXAdapter adapter)
{
InventoryItem item = Base.Item.Current;
if (item?.InventoryID != null)
{
string gIName = "BLOG-Transactions";
if (CallGIbyScreen) gIName = "BLOG01GI";
string sParameter1Name = "InventoryID";
string sParameter1Value = item.InventoryCD;
string url = String.Format(
urlFormat, giURL, gIName,
sParameter1Name, sParameter1Value
);
throw new PXRedirectToUrlException(
url, PXBaseRedirectException.WindowMode.New,
true, "Transactions-GI"
);
}
else
{
return Base.inquiry.Press(adapter);
}
}
#endregion
As you can see in the code above, we get the current InventoryItem from the Stocked Items screen that we are on. We define some variables with values specific to the GI we want to access. In this form, we can copy this code for every menu item we want to make for GI access and simply update for the specific GI. Of course, you could convert the bulk of this code to call a reusable method and pass the necessary values through to it. The code is defined to allow calling the GI by name, but since we set CallGIbyScreen to true, we will simplify our URL to a screen ID. Once we get all our values set, we simply redirect to the GI.
Now that the hard work is done, let’s add our new action(s) to the menu. We will override Initialize, call the base initialization code, override our giURL and urlFormat variables when calling the GI’s by Screen ID, and then add our new GI menu item to the Inquiry menu.
#region Initialize
public override void Initialize()
{
base.Initialize();
if (CallGIbyScreen)
{
giURL = "~/Main?ScreenId";
urlFormat = "{0}={1}&{2}={3}";
}
Base.inquiry.AddMenuAction(transactionsInq);
}
#endregion
If your GI is defined with the parameter you specified when copying the code above, you should be able to compile your code, refresh your screen in Acumatica, and enjoy the new menu addition. Keep in mind that I modified the Stocked Items screen which already had an Inquiry menu. You will need to create a new drop down menu or use an existing one, so note that a little more is needed to define the Inquiry menu if you don’t have one already.
If you are adding many menu items for GI’s, you can add the separator to the menu in the same manner as you added the GI menu item via the Initialize override above.
Base.inquiry.AddMenuAction(menuSeparator1);