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.
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.