Working with Generic Inquiries from Code

Generic Inquiries is a powerful tool to build ‘no code customizations’ for Acumatica ERP. However, it is also a tool that may be used in code too. In this article I show couple of examples of working with Generic Inquiries from code.

Redirect to a Generic Inquiry

You can redirect user to a Generic Inquiry from code almost the same way you redirect user to any other screen. To do that, you throw special PXRedirectToGIREquiredException. This exception has several overloads with different arguments. The simplest one requires only one argument – name of a Generic Inquiry (the one you see in Inquiry Title field on Generic Inquiry Design screen). See following example:

throw new PXRedirectToGIRequiredException("CommissionData");

Another overload of that exception allows you to define Generic Inquiry parameters that you want to set. To pass parameters you use dictionary containing parameter name as a key and parameter value as a value.

Building GI Parameters Collection
Building GI Parameters Collection
Dictionary<string, string> parameters = new Dictionary<string, string>();
			parameters.Add("ARInvPaid", "1");
			parameters.Add("EndPeriod", "012015");
			throw new PXRedirectToGIRequiredException("CommissionData", parameters);

Get Results of Generic Inquiry from Code

Second useful trick is getting Generic Inquiry results from code. First of all, you’ll need to create Generic Inquiry graph. To do that, use PXGenericInqGrph.CreateInstance method. Method parameters are Generic Inquiry ID, name, parameters. As for parameters, you use the same approach as in previous example – create a dictionary with parameter name as a key and the parameter value as a value.

After creating an inquiry object, you use Results view to get data. See following example:

Dictionary<string, string> parameters = new Dictionary<string, string>();
parameters.Add("ARInvPaid", "1");
parameters.Add("EndPeriod", "012015");
parameters.Add("BeginPeriod", "012014");
PXGenericInqGrph gi = PXGenericInqGrph.CreateInstance("CommissionData", "CommissionData", parameters);
PXResultset<GenericResult> results = gi.Results.Select();

The GenericResult object contains Values collection, where you can find actual DAC instances. For instance, you can get ARTran component of the result like that:

GenericResult result = results.FirstOrDefault();
ARTran tran = result.Values["ARTran"];

Note that only fields that present in the results grid of the Generic Inquiry will be filled in such ARTran object. Every other field will be filled with null value unless one of the fields that present in the result grid has PXDependOnFieldsAttribute referencing the field.

2 Replies to “Working with Generic Inquiries from Code”

  1. Sergey, thanks for the tip on how to call GI from menu, however I have a question when we call the GI in your example does the screen show title as “CommissionData” or does it say “Sales Commission Data” and is there any way to call the GI with GI ID instead of the GI title id?

    1. Hello Harsha,
      The title will be “CommissionData”, so it will be GI name and not a Screen name.
      If you want it to display the screen name instead, you can use redirect to screen exception:
      PXSiteMapNode node = PXSiteMap.Provider.FindSiteMapNodeByScreenID(“GI000009”);
      throw new PXRedirectRequiredException(node.Url, PXGenericInqGrph.CreateInstance(),
      PXBaseRedirectException.WindowMode.New, “Drilldown”);

Leave a Reply

Your email address will not be published. Required fields are marked *