How to call a BAQ report from BPM data directive using c# code

I want to run a BAQ report from a directive BPM using c#. I have successfully done this in a customization as seen below.
Reference Assembly added: Ice.UIRptBAQReport
Ice.UI.Rpt.BAQReport.Transaction trans = new Ice.UI.Rpt.BAQReport.Transaction(oTrans);
trans.LoadBAQReportData(“usagemin”);
trans.RunDirect(“Generate”);
trans.Dispose();

My BPM data directive c# code
Reference Assembly added: Ice.Contracts.Rpt.BAQReport
Ice.Contracts.BAQReportSvcContract boBAQReport = Ice.Assemblies.ServiceRenderer.GetService<Ice.Contracts.BAQReportSvcContract>(Db);
Ice.Tablesets.BAQReportTableset dsBAQReport = new BAQReportTableset();
DataSet dsResults = boBAQReport.GetByID(“usagemin”, dsBAQReport);
DataTable result_dt = dsResults.Tables[“Results”];
I get 1 error when I check syntax:
CS1061 ‘BAQReportSvcContract’ does not contain a definition for ‘GetByID’ and no extension method ‘GetByID’ accepting a first argument of type ‘BAQReportSvcContract’ could be found (are you missing a using directive or an assembly reference?)
I get this error because I do not know the syntax for specifying the BAQ report name.
I also do not know the syntax for:
trans.RunDirect(“Generate”);
used in my customization code.

Please help !!!

Hello @R.Zimmer, thisnis the go-to reference for dynamic query in a bpm:

Also take a look at this - if you format your code like this it makes it way easier for people to read:

Thank you for your response. I need to call a BAQ Report,
not a BAQ query.
If you could help me with a Report instead of a query, that would be great!!!
Thanks,
Richard

Here’s an example that prints the baq report to a client printer. The variables are passed to the bpm from a customization.

try
{
  using (Ice.Contracts.DynamicReportSvcContract dynamicReport = Ice.Assemblies.ServiceRenderer.GetService<Ice.Contracts.DynamicReportSvcContract>(Db))
  {
    using( Ice.Contracts.BAQReportSvcContract baqReport = Ice.Assemblies.ServiceRenderer.GetService<Ice.Contracts.BAQReportSvcContract>(Db) )
    {
     
      var rptTs = dynamicReport.GetByID("InvLabel");
      var baqRptDS = baqReport.GetNewBAQReportParam("InvLabel");
      baqRptDS.BAQReportParam[0].BAQRptID = "InvLabel";
      baqRptDS.BAQReportParam[0].BAQID = "InventoryLabelData";
      baqRptDS.BAQReportParam[0].ReportID = "InvLabel";
      baqRptDS.BAQReportParam[0].ReportStyleNum = reportStyle;
      baqRptDS.BAQReportParam[0].Option01 = tranNum.ToString();
      baqRptDS.BAQReportParam[0].AutoAction ="SSRSClientPrint";
      baqRptDS.BAQReportParam[0].PrinterName = printer;
      baqRptDS.BAQReportParam[0].WorkstationID = workstationID;
      baqRptDS.BAQReportParam[0].SSRSRenderFormat = "PDF";
      baqRptDS.BAQReportParam[0].AttachmentType = "PDF";
      baqRptDS.BAQReportParam[0].Summary = false;
      baqRptDS.BAQReportParam[0].RecurringTask = false;
      baqRptDS.BAQReportParam[0].SSRSEnableRouting = false;
      baqRptDS.BAQReportParam[0].ArchiveCode = 0;
      baqRptDS.BAQReportParam[0].AgentSchedNum = 0;
      baqRptDS.BAQReportParam[0].AgentID = "Main";
      baqRptDS.BAQReportParam[0].AgentTaskNum = 0;
      baqRptDS.BAQReportParam[0].RowMod = "A";
      baqRptDS.BAQReportParam[0].RptPageSettings = pageSettings;
      
      printerSettings = Regex.Replace(printerSettings, @"Copies=\d*", @"Copies=" + quantity.ToString() );
      
      baqRptDS.BAQReportParam[0].RptPrinterSettings = printerSettings;
      rptTs.BAQRptOptionFld[0].FieldValue = tranNum.ToString();
      
      DynamicReportDataSet rptDs = new DynamicReportDataSet();
      
      DatasetAdapter.CopyTSTableToDataTable<BAQReportRow, DynamicReportDataSet.BAQReportDataTable>(rptTs.BAQReport, rptDs.BAQReport);
      DatasetAdapter.CopyTSTableToDataTable<BAQRptFilterRow, DynamicReportDataSet.BAQRptFilterDataTable>(rptTs.BAQRptFilter, rptDs.BAQRptFilter);
      DatasetAdapter.CopyTSTableToDataTable<BAQRptOptionFldRow, DynamicReportDataSet.BAQRptOptionFldDataTable>(rptTs.BAQRptOptionFld, rptDs.BAQRptOptionFld);
      DatasetAdapter.CopyTSTableToDataTable<BAQRptSortRow, DynamicReportDataSet.BAQRptSortDataTable>(rptTs.BAQRptSort, rptDs.BAQRptSort);
      DatasetAdapter.CopyTSTableToDataTable<BAQRptSortFldRow, DynamicReportDataSet.BAQRptSortFldDataTable>(rptTs.BAQRptSortFld, rptDs.BAQRptSortFld);
      
      rptDs.AcceptChanges();
      StringWriter writer = new StringWriter();
      rptDs.WriteXml(writer);
      baqRptDS.BAQReportParam[0].Filter1 = writer.ToString();
      
      baqReport.SubmitToAgent(baqRptDS, "Main", 0, 0, "Ice.UIRpt.BAQReport;InvLabel");
      
      
    }
      
  
  }
}
catch (Exception ex)
{
  this.PublishInfoMessage("An error occured trying to print report." + ex.Message, Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, "", "");
}

'''
2 Likes

Thank you for your reply. I think that this solution is using vb. It would be great if you I could show me the same solution in c#? Any idea what it would look like in c#?

Thanks,
Richard

That is most definitely c#, not vb

No problem. It would look like this, since it’s c# ;).

1 Like

Sorry about that, my bad. I added 2 reference assemblies.

  1. Ice.Contracts.BO,DynamicReport
  2. Ice.Contracts.Rpt.BaqReport
    And still got these errors. I must be missing other reference assemblies. Would you please tell me which ones?
    Thanks,
    Richard
    |CS1011|Empty character literal||—|---|
    |CS1002|; expected|
    |CS1010|Newline in constant|
    |CS1011|Empty character literal|
    |CS1002|; expected|
    |CS0103|The name ‘reportStyle’ does not exist in the current context|
    |CS0103|The name ‘tranNum’ does not exist in the current context|
    |CS0103|The name ‘printer’ does not exist in the current context|
    |CS0103|The name ‘workstationID’ does not exist in the current context|
    |CS0103|The name ‘pageSettings’ does not exist in the current context|
    |CS0103|The name ‘printerSettings’ does not exist in the current context|
    |CS0103|The name ‘printerSettings’ does not exist in the current context|
    |CS0103|The name ‘quantity’ does not exist in the current context|
    |CS0103|The name ‘Regex’ does not exist in the current context|
    |CS0103|The name ‘printerSettings’ does not exist in the current context|
    |CS0103|The name ‘tranNum’ does not exist in the current context|
    |CS0246|The type or namespace name ‘DynamicReportDataSet’ could not be found (are you missing a using directive or an assembly reference?)|
    |CS0246|The type or namespace name ‘DynamicReportDataSet’ could not be found (are you missing a using directive or an assembly reference?)|
    |CS0246|The type or namespace name ‘DynamicReportDataSet’ could not be found (are you missing a using directive or an assembly reference?)|
    |CS0246|The type or namespace name ‘DynamicReportDataSet’ could not be found (are you missing a using directive or an assembly reference?)|
    |CS0246|The type or namespace name ‘DynamicReportDataSet’ could not be found (are you missing a using directive or an assembly reference?)|
    |CS0246|The type or namespace name ‘DynamicReportDataSet’ could not be found (are you missing a using directive or an assembly reference?)|
    |CS0246|The type or namespace name ‘DynamicReportDataSet’ could not be found (are you missing a using directive or an assembly reference?)|
    |CS0246|The type or namespace name ‘StringWriter’ could not be found (are you missing a using directive or an assembly reference?)|
    |CS0246|The type or namespace name ‘StringWriter’ could not be found (are you missing a using directive or an assembly reference?)|

Here’s the additional references I have:

image

image

Most of the “does not exist in the current context” errors relate to my variables. I initiated them outside the code block in ‘set field’ widgets using values passed from a customization, so you would need to create new ones or pass in hard text values.

Richard
Printing a report directly from a data directive is a Horrendous idea. Data Directives are a giant hammer and running a report takes a LONG time this is going to bring your epicor to its knees.

can I ask why you need to do this at a Data Directive Level? (what is the end goal)

Have you looked into Auto Print?

Adam, Thank you for your additional usings.

Jose,
My end goal is to print a BAQ report to a local printer on each Mes computer which uses the same Epicor user name without doing a preview to pdf because the printers are label printers and I do not want the Mes user to have to click on the pdf to send it to the label printer. I am currently using the auto print in a BPM data directive on labordtl change with qty complete produce the label to print but the user has to do the pdf to printer thing each time they do an end activity which takes too much time. I know that Epicor prints directly to a label printer when the Mes user clicks Print Tags on the end activity form even though each MES user uses the same user name but I don’t know how?
Any information would be helpful.
Thanks,
Richard

If you are printing labels, I would really look into bartender. It works way better than ssrs to print to label printers, and you can bypass ssrs altogether of you want.

1 Like

Hey Adam,

Thank you for your response. I understand everything about the variables needing to be set by me. I do not understand why I am getting the below error 6 times in your code?

Please help !!!
Thanks,
Richard

|CS0246|The type or namespace name ‘DynamicReportDataSet’ could not be found (are you missing a using directive or an assembly reference?)|

I’m not sure, did you add the using Ice.BO? That portion of the code was from this post:

Hey Adam,

Thank you for your response.

I forgot the ; after the using Ice.BO. I put the ; in and that fixed the problem.

Now I am able to run it but I get the error:

An error occurred trying to print report. Invalid AgentID.

You have “Main” as the agent id?

Any ideas?

Thanks,
Richard

Check System Agent Maintenance for the agent ID.

Hey Adam,

Thank you for your response.

I got it working by using a value in quotes for the workstationid that I got from a trace from my test computer. Amazing!

I have been trying to figure out how to get the workstationid from a customization in a form in c# but have struck out.

Would you please give me your c# code from your customization to get the workstationid and then I will try to figure out how to transfer it from the customization to my BPM via bpmcontextdata.

Thanks,
Richard

Hey Richard,

Good to hear. I used

EpiDataView callContextBpm = (EpiDataView)(oTrans.EpiDataViews["CallContextBpmData"]);
System.Data.DataRow callContextBpmRow = callContextBpm.CurrentDataRow;
callContextBpmRow.BeginEdit();
callContextBpmRow["Character02"] = Ice.Lib.Report.EpiReportFunctions.GetWorkStationID((Ice.Core.Session)oTrans.Session);
callContextBpmRow.EndEdit();

in a customization. You can get the workstation in the data directive too:

Looks like you’re trying to print labels. Have you looked into BarTender? For what it can do, easy of use, flexibility, and integrability it’s dirt cheap. And I’m a cheap A-Hole ask @josecgomez he loves to remind me of that.

just this part :stuck_out_tongue: