0% found this document useful (0 votes)
167 views13 pages

12-How To Call An Epicor BAQ Report From Customization - GingerHelp

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
167 views13 pages

12-How To Call An Epicor BAQ Report From Customization - GingerHelp

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

5/16/24, 3:46 PM How to Call an Epicor BAQ Report From Customization — GingerHelp

[email protected]

E P I C O R : H OW TO CA L L A
B AQ R E P O RT F R O M W I T H I N
A C U STO M I Z AT I O N
ADAM ELLIS · JUNE 18, 2020

We have already documented how you can call a BAQ from within a
customization on this article but what if you want to run a BAQ Report?
While there is more than one way, I find the most efficient methodology is
to simply launch the BAQ Report dialog, auto-populate the fields to run
the report, and execute the event to either print or preview the report.
And we can do that without the user having any clue to the complexity
behind the scenes by using scenario #3 from this guide. If you follow that
guide and reference Ice.UIRpt.BAQReport then you can use a code
snippet like this to easily print or preview any BAQ Report that you like:

// Establish your reference to the BAQ Report UI


Ice.UI.Rpt.BAQReport.Transaction trans = new Ice.UI.Rpt.BA

// Load the specific BAQ Report by ID you are interested i


trans.LoadBAQReportData("MyBAQReport");

// Fill in the parameters to run the report. You can find


// by using field help on the BAQ Report dialog.
EpiDataView edvData = (EpiDataView)trans.EpiDataViews["Rep
edvData.dataView[edvData.Row]["field1"] = "PART123";
edvData.dataView[edvData.Row]["field2"] = "CUSTOMERXYZ";

https://www.gingerhelp.com/knowledgebase-epicor-erp/epicor-how-to-call-a-baq-report-from-within-a-customization 1/13
5/16/24, 3:46 PM How to Call an Epicor BAQ Report From Customization — GingerHelp

// Submit to system agent. You can do either a preview or


trans.RunDirect("Preview");

// Clean up the objects


edvData.Dispose();
trans.Dispose();

That is all there is to it!

LET'S CHAT ABOUT YOUR NEXT BAQ


PROJECT

AUTHOR: Adam Ellis


Adam Ellis is the owner of
GingerHelp. Adam is a lifelong
entrepreneur and has extensive ERP
and mobile software knowledge
through his consulting and
management experience. He has a
passion for exploring innovative ideas
and how they can change the status
quo. Connect with Adam on LinkedIn
to learn more about his involvement
in the ERP space.

FACEBOOK TWI TTER PINTEREST 1 LIKE

https://www.gingerhelp.com/knowledgebase-epicor-erp/epicor-how-to-call-a-baq-report-from-within-a-customization 2/13
5/16/24, 3:46 PM How to Call an Epicor BAQ Report From Customization — GingerHelp

COMMENTS (12) Newest First

Preview POST COMMENT…

Carla 9 months ago · 0 Likes

How do i pass through a field present on the screen rather than

edvData.dataView[edvData.Row]["field1"] = "PART123";

Jeanne A. Singagliese A year ago · 0 Likes

I realize this is an old post but I hope you will be able to answer my question. How
would I specify to print to the client printer instead of the server printer? If I put in
"Print" it defaults to the server printer. I have not been able to find anything that tells
me how to print to the client printer.

Dave 3 years ago · 0 Likes

We have a grid to select the records that need to be printed through a BAQ report.
We need each line selected printed, but we would like to combine all the records
together and send as on print batch job.

Dave 3 years ago · 0 Likes

https://www.gingerhelp.com/knowledgebase-epicor-erp/epicor-how-to-call-a-baq-report-from-within-a-customization 3/13
5/16/24, 3:46 PM How to Call an Epicor BAQ Report From Customization — GingerHelp

How do you pick the number of copies you want printed of each record?

Adam Ellis 3 years ago · 0 Likes

Dan,

A BAQ that uses 'Filters' is a bit more challenging than one that uses 'Options' to input
the parameters to run the report. Quick thought - what if you just made a second BAQ
Report definition that only uses an option field to input the case number? You could
still point to the same RDL and BAQ, the only difference would be on this version you
have a plain text box to input the case number as opposed to the nice lookup view.
And you wouldn't even need to put it on the menu anywhere.

If you do want to keep plugging away at the path of getting the filter list input working
it is definitely possible - I've done it before but could not track down a nice snippet for
you. In short, that Filter1 object needs to get populated with a DynamicReportDataSet
object for it to run.

Hope this helps,


Adam

Dan Ramirez 3 years ago · 0 Likes

Thanks, Adam. I did end up going down the path of using an option instead of
a filter. That worked well.

Dan Ramirez 3 years ago · 0 Likes

Adam,
Thanks for posting this for all to see. I am trying this out with a BAQ Report and I feel
I'm 97% of the way there. I can get the form to pop-up a PDF when I click a button -
but it's not passing the filter. I did the Field Help and it says the field is named
FilterList1. It's not getting to the BAQ Report, though. It ends up printing HDCaseNum =
1 instead of the number I pass along. Is there an obvious thing I'm missing, here?
https://www.gingerhelp.com/knowledgebase-epicor-erp/epicor-how-to-call-a-baq-report-from-within-a-customization 4/13
5/16/24, 3:46 PM How to Call an Epicor BAQ Report From Customization — GingerHelp

Adam Ellis 3 years ago · 0 Likes

Yeah, it has been a while but I know exactly what you are trying to accomplish. The
last time I did it were were unable to customize the Crystal Reports viewer that Epicor
has in place by default but we were able to add our own Crystal Reports Viewer
control to the Epicor form and bind that ReportDocument to is in order to see the
results. I wish I still had the snippet - I feel like you are like 98% of the way there.

Martyn 3 years ago · 0 Likes

Again - thank you for pasting the code. I do appreciate that.

Unfortunately, this is not quite what I am looking for. The PrintDialog was useful
portion.

Below is the code I currently have....

// dtReport is the DataTable supported for CrystalReport via ADO (XML)


using(var crystalReport = new ReportDocument())
{
var printerName = GetPrinter(); // This is the PrinterDialog load
if(printerName == "")
{
EpiMessageBox.Show("No printer selected. Cancelling");
}
else
{
crystalReport.Load("location\of\crystal\report.rpt");
crystalReport.DataSourceConnections.Clear();
crystalReport.SetDataSource(dtReport);
crystalReport.PrintOptions.NoPrinter = true;
crystalReport.PrintOptions.PrinterName = printerName;
crystalReport.PrintOptions.PaperSource =
CrystalDecisions.Shared.PaperSource.Auto;

https://www.gingerhelp.com/knowledgebase-epicor-erp/epicor-how-to-call-a-baq-report-from-within-a-customization 5/13
5/16/24, 3:46 PM How to Call an Epicor BAQ Report From Customization — GingerHelp

crystalReport.PrintToPrinter(1, false, 0, 0);


crystalReport.Close();
}
}

The best way to explain what I am looking for is to refer to a Dashboard. Some
dashboards allow you to print a Report via the 'Actions' menu. Once clicked it opens a
'Preview Window'

I believe this Preview Window is different depending on if you are using SSRS or
Crystal Report. For the Crystal Report one (which we are using) the popup window
shows the report results with "SAP CRYSTAL REPORT" written at the top-right of the
window.

It is that window I would like to display programatically via customization. I have


looked about but not had much luck finding an answer.

Again - thank you for helping. Your posts have been very interesting and will be
visiting more.

Martyn 3 years ago · 0 Likes

THANK YOU SO MUCH FOR PASTING THIS CODE!

I will see what I can get out of this. If I get it to work I will post back the code if any
different.

Adam Ellis 3 years ago · 0 Likes

Martyn,

I think I've got a snippet here that is actually pretty similar to what you're looking to
do. It has been a while since I last used this but hopefully it points you in the right
direction:

https://www.gingerhelp.com/knowledgebase-epicor-erp/epicor-how-to-call-a-baq-report-from-within-a-customization 6/13
5/16/24, 3:46 PM How to Call an Epicor BAQ Report From Customization — GingerHelp

====
This snippet of code shows how to use reflection to access the functionality of the
Crystal Reports runtime without explicitly defining a reference to the DLLs. This
specific example would be most useful in something like Epicor where you want to
leverage the runtime assemblies without requiring end users copy DLL files into their
Epicor client folder. The overall technique here, though, would be useful for any .Net
assembly that is registered in the global assembly cache.
using System;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Windows.Forms;
using Epicor.Mfg.BO;
using Epicor.Mfg.UI;
using Epicor.Mfg.UI.Adapters;
using Epicor.Mfg.UI.Customization;
using Epicor.Mfg.UI.ExtendedProps;
using Epicor.Mfg.UI.FormFunctions;
using Epicor.Mfg.UI.FrameWork;
using Epicor.Mfg.UI.Searches;
using System.Runtime.InteropServices;
using System.Drawing.Printing;
using System.Drawing;
using System.Reflection;

public class Script


{
// ** Wizard Insert Location - Do Not Remove 'Begin/End Wizard Added Module Level
Variables' Comments! **
// Begin Wizard Added Module Level Variables **

// End Wizard Added Module Level Variables **

// Add Custom Module Level Variables Here **

https://www.gingerhelp.com/knowledgebase-epicor-erp/epicor-how-to-call-a-baq-report-from-within-a-customization 7/13
5/16/24, 3:46 PM How to Call an Epicor BAQ Report From Customization — GingerHelp

// These lines call the Crystal runtime via reflection in order to a


Type reportDocumentType = Type.GetType("CrystalDecisions.Crysta
ConstructorInfo reportDocumentConstructor;
object reportDocumentObject;
MethodInfo reportDocumentLoadMethod;
MethodInfo reportDocumentSetDataSourceMethod;
MethodInfo reportDocumentPrintToPrinterMethod;

public void InitializeCustomCode()


{
// ** Wizard Insert Location - Do not delete 'Begin/End Wizard A
// Begin Wizard Added Variable Initialization

// End Wizard Added Variable Initialization

// Begin Wizard Added Custom Method Calls

// End Wizard Added Custom Method Calls

// These references are used to access various elements of the C


reportDocumentConstructor = reportDocumentType.GetConstructor(Ty
reportDocumentObject = reportDocumentConstructor.Invoke(new obje
// This line grabs a reference to the load method on the ReportD
reportDocumentLoadMethod = reportDocumentType.GetMethod("Lo
// This line grabs a reference to the SetDataSource method on th
reportDocumentSetDataSourceMethod = reportDocumentType.GetMethod
// This line grabs a reference to the PrintToPrinter method on t
reportDocumentPrintToPrinterMethod = reportDocumentType.GetMetho
}

public void DestroyCustomCode()


{
// ** Wizard Insert Location - Do not delete 'Begin/End Wizard A
https://www.gingerhelp.com/knowledgebase-epicor-erp/epicor-how-to-call-a-baq-report-from-within-a-customization 8/13
5/16/24, 3:46 PM How to Call an Epicor BAQ Report From Customization — GingerHelp

// Begin Wizard Added Object Disposal

// End Wizard Added Object Disposal

// Begin Custom Code Disposal


reportDocumentType = null;
reportDocumentConstructor = null;
reportDocumentObject = null;
reportDocumentLoadMethod = null;
reportDocumentSetDataSourceMethod = null;
reportDocumentPrintToPrinterMethod = null;
// End Custom Code Disposal
}

private void btnPrintBagLabels_Click(object sender, System.EventArgs


{
PrintLabels("BagLabels", "c:\myreport.rpt");
}

private void PrintLabels(string strLabelType, string strRptFile)


{

Epicor.Mfg.BO.DynamicQuery dy;
Epicor.Mfg.BO.QueryDesignDataSet data;
DataSet baqResult;
bool recSelected = false;
string whereClause = "";

try {
dy = new Epicor.Mfg.BO.DynamicQuery(((Epicor.Mfg.Core.Session

// Grab a reference to the generic BAQ used by al la


data = dy.GetQueryByID(((Epicor.Mfg.Core.Session)oTrans.Sessi

https://www.gingerhelp.com/knowledgebase-epicor-erp/epicor-how-to-call-a-baq-report-from-within-a-customization 9/13
5/16/24, 3:46 PM How to Call an Epicor BAQ Report From Customization — GingerHelp

// Apply the criteria to the BAQ


foreach (DataRow dr in data.QueryWhereItem.Rows) {
if (dr["FieldName"].ToString() == "Key1&quot
dr["RValue"] = strLabelType;
}
}

// Execute the BAQ


baqResult = dy.Execute(data);
baqResult.DataSetName = "ReportResults";

// Prompt for the printer


// Create the print dialog object and set options
PrintDialog pDialog = new PrintDialog();
// Display the dialog. This returns true if the user pre
System.Windows.Forms.DialogResult print = pDialog.ShowDi

if (print != DialogResult.OK) {


EpiMessageBox.Show("No printer selected. Print job no
return;
}

// Load the RPT file defined in loadParametersArray into the


object[] loadParametersArray = new object[] { strRptFile
object loadResult = reportDocumentLoadMethod.Invoke(reportDoc

// Next we need to set location on the report using the same


object[] setDataSourceParametersArray = new object[] { b
object setDataSourceResult = reportDocumentSetDataSourceMetho

// Now print the report


object[] printParametersArray = new object[] { pDialog.P
object printResult = reportDocumentPrintToPrinterMethod.Invok

https://www.gingerhelp.com/knowledgebase-epicor-erp/epicor-how-to-call-a-baq-report-from-within-a-customization 10/13
5/16/24, 3:46 PM How to Call an Epicor BAQ Report From Customization — GingerHelp

} catch (Exception ex) {


EpiMessageBox.Show(ex.InnerException.ToString());
} finally {
dy = null;
data = null;
baqResult = null;
}
}

Martyn 3 years ago · 0 Likes

Hi. Thanks for this. One question... I have created a Customization (rather than a
dashboard due to the filtering options) and would like to generate a crystal report
based on the results in the UltraGrid. I am using the Crystal Reports
CrystalDescisions/ReportDocument to create it and send it to OneNote.

However, I would love to be able to send it straight to the Preview Window in Epicor
like the Reports open in a Dashboard. I believe the trans.RunDirect("Preview") is
exactly that!

Can I bypass loading the information from a BAQReport and, instead, be able to use
the name (and location) of the report and results in UltraGrid straight into the
Previewer?

Hope the above makes sense? Thank you.

PREVIOUS

HOW TO EMAIL AN EPICOR BAQ REPORT FROM A


CUSTOMIZATION
EPICOR CUSTOMIZATION, EPICOR ERP, EPICOR BAQ

NEXT

USING LINQ (LANGUAGE INTEGRATED QUERY) IN EPICOR BPMS


EPICOR BPM, EPICOR CUSTOMIZATION, EPICOR ERP

https://www.gingerhelp.com/knowledgebase-epicor-erp/epicor-how-to-call-a-baq-report-from-within-a-customization 11/13
5/16/24, 3:46 PM How to Call an Epicor BAQ Report From Customization — GingerHelp

LET’S CHAT!

CONTACT US

GINGERHELP, SERVIC PRODU KNOWLEDGE


LLC ES CTS BASE

8685 Fox Epicor ERP Epicor ERP Epicor ERP Articles


Lake Road Consulting Extensions Infor VISUAL Articles
Sterling, OH P21 ERP Infor Dynamics 365
44276 USA Consulting VISUAL ERP Articles
Infor Extensions Crystal Reports
 VISUAL ERP Articles
[email protected] Consulting SSRS Articles
Dynamics Bezlio for Mobile
365 ERP Articles
Consulting
SSRS
Developer
Services
Crystal
Reports
Consulting

https://www.gingerhelp.com/knowledgebase-epicor-erp/epicor-how-to-call-a-baq-report-from-within-a-customization 12/13
5/16/24, 3:46 PM How to Call an Epicor BAQ Report From Customization — GingerHelp

GingerHelp is an
independent consulting
practice with no direct
© 2019 - 2023 GingerHelp,
affiliation with Epicor® or
LLC
Infor®.

Terms & Conditions |


Epicor®, Vantage®, and Privacy Policy
Prophet 21™ are registered
trademarks of Epicor
Software Corporation®.
Infor® and VIUSAL® are
registered trademarks of
Infor®.
Crystal Reports® is a
registered trademark of SAP
AG.

https://www.gingerhelp.com/knowledgebase-epicor-erp/epicor-how-to-call-a-baq-report-from-within-a-customization 13/13

You might also like