C# Print Crystal (BAQ) Rpt directly to printer

So the programmatic printing topic has been done and redone numerous times; I thought I’d definitely find sample code that works for my specific situation. Well… “Uncle”!

Sitrep:
I’ve created a BAQ Report that has 1 option field which takes an alphanumeric ID. The query itself would return all records in my UD100 table, but the report uses an option field to grab just the UD100 record I am looking for (Key1 field). This works fine when printing from my customized application.

Challenge:
I’m trying to bypass all dialog boxes and send the crystal report straight to the default printer for this dedicated workstation. Therefore, on ButtonClick(), print!

Acceptable solution:
I’ll be happy just creating the XML. There’s another @josecgomez post that uses FileSystemWatcher to send the XML to print, so I may try that.

Current location:
I’ve cobbled together (and reduced) posts by @josecgomez and @hkeric.wci (they deal w/SSRS output, but okay), and there are other examples out there in the netherweb.

I’ve reduced it all to the following. But, when run, it goes active in report monitor and runs until I stop the task agent. It does create a properly formatted XML file, but it includes all records from the UD table.

private void PrintTicket()
{
string BAQ = “MDI-RPT-ScaleTkt”;
string report = “MDI_RPT-ScaleTk”;
string format = “MDI_RPT-ScaleTk”;
string agentID = “SystemTaskAgent”;
string reportname = “Scale Ticket”;
Session otSession = (Session)oTrans.Session;
string workStation = Ice.Lib.Report.EpiReportFunctions.GetWorkStationID(otSession);
string userID = otSession.UserID;
string ticketNum = edv.CurrentDataRow[“Key1”].ToString();
try
{
var baqR = WCFServiceSupport.CreateImpl<Ice.Proxy.Rpt.BAQReportImpl>(otSession, Epicor.ServiceModel.Channels.ImplBase<Ice.Contracts.BAQReportSvcContract>.UriPath);
var dynamicReport = WCFServiceSupport.CreateImpl<Ice.Proxy.BO.DynamicReportImpl>(otSession, Epicor.ServiceModel.Channels.ImplBase<Ice.Contracts.DynamicReportSvcContract>.UriPath);
//var rptMonitor = WCFServiceSupport.CreateImpl<Ice.Proxy.BO.ReportMonitorImpl>((Session)oTrans.Session, Epicor.ServiceModel.Channels.ImplBase<Ice.Contracts.ReportMonitorSvcContract>.UriPath);

  	// GET DEFAULT REPORT PARAMETERS
  	var rptDs = dynamicReport.GetByID(report);
  	var baqRptDS = baqR.GetNewBAQReportParam(report);
  	baqRptDS.BAQReportParam[0].AutoAction="PREVIEW";
  	baqRptDS.BAQReportParam[0].WorkstationID=workStation;
  	baqRptDS.BAQReportParam[0].UserID=userID;
  	baqRptDS.BAQReportParam[0].SSRSRenderFormat = format;
  	baqRptDS.BAQReportParam[0].AttachmentType = format;
  	baqRptDS.BAQReportParam[0].BAQRptID=(report);
  	baqRptDS.BAQReportParam[0].ReportID=(report);
  	baqRptDS.BAQReportParam[0].Summary = false;
  	baqRptDS.BAQReportParam[0].ReportStyleNum = 1;
  	baqRptDS.BAQReportParam[0].BAQID=(BAQ);
  	baqRptDS.BAQReportParam[0].ReportTitle = reportname;
  	baqRptDS.BAQReportParam[0].Option01 = ticketNum; //  Just ONE ticket

  	rptDs.AcceptChanges();
  	StringWriter writer = new StringWriter();
  	rptDs.WriteXml(writer);
  	baqRptDS.BAQReportParam[0].Filter1 = writer.ToString();

  	baqR.SubmitToAgent(baqRptDS, agentID, 0, 0,"Epicor.Mfg.UIRpt.BAQReport");
  }
  catch (Exception ex)
  {
  	MessageBox.Show("An error occured trying to print report." + ex.Message);
  
  }

Does anyone care to offer a suggestion on this very old and tired topic?

Is BAQ Report Style (StyleNum=1) setup as a Crystal Report?

Hey @ckrusen, thatnks for the response. Yes. Style 1 is defined as a crystal report.

When I have programmed printing a BAQ report directly from a button, the Filter1 was much more extensive. Here is an example from one that I have worked on:

dsBAQRpt.Tables[“BAQReportParam”].Rows[0][“Filter1”] = “<DynamicReportDataSet xmlns="http://www.epicor.com/Ice/300/BO/DynamicReport/DynamicReport\”>ShaftInspectionShaft Inspection ReportShaft Inspection ReportInspectionReportDatafalsefalsefalsefalseShaftInspectionShaftInspection.rdlShaftInspectionJobHeadJobNumJobEntryAdapter1JobNumJobJobJobHead_JobNumtrueJobNumfalse0nvarcharFilterList1‘" + Convert.ToString(edvCallContextBpmDataRow[“ShortChar01”]) + "’0";

1 Like

Wow. @WildERP , I appreciate the response, but I’m struggling to decipher.
Since the variable “ticketNum” contains the selection criteria for my BAQ, would I be correct in interpretting your code as…

dsBAQRpt.Tables[“BAQReportParam”].Rows[0][“Filter1”] = ticketNum; ???

I’m certain I have that wrong, but there’s alot going on in your post as well as the code that I’m copying from. I was fine with adapters and business objects, but this WCF and XML stuff… Whew!

Do you have a trace from running the report manually with the correct filter? That should give you the exact syntax required. I don’t believe it is just your value to filter by. If you send me the trace I can tell you what it should be.

I have a trace and the XML report file. It’s a single label that’s being printed, so it shouldn’t be too much data to sift through.

Jim, I’m hesitant to post this info… the trace is 5K lines long (I selected all the options in the tracing dialog)
I can format to summarize, but is it okay to dump all that data here?

You can email it to me directly at jim_rogers@wilderp.com and I can take a look.

On its way Jim. Thanks much!

Okay Jim. That’s one Major Success! The code now drops a single label (XML) in the appropriate EpicorData folder. Thanks for the assist.

My code executes the BAQ report via the system task agent, but creates a task that keeps running. I’m pretty sure its not doing anything because the label (XML) has already been created, but the task remains active until I restart the task agent. Any thoughts?

baqR.SubmitToAgent(baqRptDS, agentID, 0, 0,"Epicor.Mfg.UIRpt.BAQReport");

Andrew, glad it is working. Two changes I would make to your code:

Add the line

baqRptDS.BAQReportParam[0].AgentID = agentID;

Modify your submitToAgent line to be as follows:
baqR.SubmitToAgent(baqRptDS, agentID, 0, 0,"Epicor.Mfg.UIRpt.BAQReport;" + report);

1 Like

I’ve made the edits, but he task runs and remains active, Jim.
My code calls for the report to be previewed, but I haven’t provided any details on Crystal or paging. Some of the examples I’ve seen include all sorts of code defining the Crystal environment and page sizes, printer names, etc. Could this omission be the problem, in your view?

1 Like

Andrew,
I would run a trace while running the report via the button and also when running it manually to verify you have all the parameters set correctly in the code. Specifically compare the SubmitToAgent calls from both runs to see what is different.

Thanks Jim. I think that’s gonna be my best option - when/if I figure this out, I’ll have to post something here. This topic seems to still frustrate lots of folks and there aren’t definitive guides available - just bits of code that’s been shared a bunch of times. I do appreciate your assistance, however. I’m closer now than I was.