BAQ Report Print from customization

Hi,

Need some of the sample how can I call specific BAQ report from customization, pass partnum param and submit directly for printing to agent.
I was trying a lot of scripts but non of them worked. Might be someone has a code snippet?

There are some good posts on here. Adding a BAQ Report to the Actions Tab under MRP Job Tracker

Sorry when I read your post I wasn’t at my PC so it wasn’t easy to copy/paste. But this is what you’re looking for. This is for a button click event but you can put it on whatever UI interaction you’re looking for. Change the “CaseReport” to whatever your BAQ Report is called. Update the section for Get current case number to reflect whatever form you’re in and replace the caseNum with partNum. That’s pretty much it. This will pop up a Print Preview. If you don’t want that, remove the RunDirect bit.

private void btnPrint_Click(object sender, System.EventArgs args)
	{
		// Establish your reference to the BAQ Report UI
		Ice.UI.Rpt.BAQReport.Transaction trans = new Ice.UI.Rpt.BAQReport.Transaction(oTrans);
	
		// Load the specific BAQ Report by ID you are interested in
		trans.LoadBAQReportData("CaseReport");

		// Get the current Case Number
		var myEDView = oTrans.Factory("HDCase");
		var currentRow = myEDView.dataView[myEDView.Row];
		int caseNum = Convert.ToInt32(currentRow["HDCaseNum"]);
	
		// Fill in the parameters to run the report.  You can find these
		// by using field help on the BAQ Report dialog.
		EpiDataView edvData = (EpiDataView)trans.EpiDataViews["ReportParam"];
		edvData.dataView[edvData.Row]["field1"] = caseNum;
	
		// Submit to system agent.  You can do either a preview or print here
		trans.RunDirect("Preview");
	
		// Clean up the objects
		edvData.Dispose();
		trans.Dispose();
	}

I just solved this problem last night. All the code examples are outdated. The one above will work for previewing. When I arrive home I will try to post how to use the adapters correctly.

This should get you started.


//References:
//Ice.Adapters.SysAgent.dll
//Ice.Adapters.DynamicReport.dll
//Ice.Contracts.BO.DynamicReport.dll
//Ice.Contracts.Rpt.BAQReport.dll
//Ice.UIRpt.BAQReport.dll

using Ice.Core;
using Ice.Lib.Adapters;
using System.IO;

            
            
    Session otSession = (Session)oTrans.Session;
    
    //Set the workstationID
    string workStation = Ice.Lib.Report.EpiReportFunctions.GetWorkStationID(otSession);
    
    using (var objSysAgent = new SysAgentAdapter(oTrans))
    {
        objSysAgent.BOConnect();
        objSysAgent.GetDefaultTaskAgentID(out agentID);
        if (!string.IsNullOrEmpty(agentID)) 
        { 
            agentID = "SystemTaskAgent"; 
        }
    }


    BAQReportAdapter baqR = new BAQReportAdapter(oTrans);
    baqR.BOConnect(); //There is no dispose on this object. Why?

    baqR.GetNewBAQReportParam("msePCIDContents");
    
    Ice.Rpt.BAQReportDataSet.BAQReportParamRow paramBAQ = baqR.ReportDataSet.BAQReportParam[0];
    
    paramBAQ.BAQID = "msePCIDContentsReport";
    paramBAQ.ReportTitle = "Pallet Summary Report";
    paramBAQ.BAQRptID = "msePCIDContents";
    paramBAQ.AutoAction = "SSRSClientPrint";
    paramBAQ.PrinterName = "Accounting";
    paramBAQ.AgentID = agentID;
    paramBAQ.RptPageSettings = "Color=True,Landscape=False,AutoRotate=False,PaperSize=[Kind=\"Letter\" PaperName=\"Letter\" Height=1100 Width=850],PaperSource=[SourceName=\"Auto Tray Select\" Kind=\"AutomaticFeed\"],PrinterResolution=[Kind=\"Custom\" X=600 Y=600]";
    paramBAQ.RptPrinterSettings = "PrinterName=\"Accounting\",Copies=1,Collate=False,Duplex=Simplex,FromPage=1,ToPage=0";
    paramBAQ.WorkstationID = workStation;
    paramBAQ.Option01 = pcid;

    DynamicReportAdapter dynRpt  = new DynamicReportAdapter(oTrans);
    dynRpt.BOConnect();
    
    dynRpt.GetNewBAQReport();
    
    dynRpt.GetByID("msePCIDContents");
    
    dynRpt.DynamicReportData.BAQRptOptionFld[0].FieldValue = pcid;
    

    StringWriter writer = new StringWriter();
    dynRpt.DynamicReportData.WriteXml(writer);
    paramBAQ.Filter1 = writer.ToString();

    baqR.RunDirect();

    dynRpt.Dispose();

1 Like

Hello,
when i run the following code, i got bad sql statement. but if i run from the kinetic, it is ok. i don’t know where is wrong.

thanks,

Eddy

 using (Session session = new Session("xxx", "xxx", "xxx"))
            {

                ILauncher oTrans = new ILauncher(session);

                session.CompanyID = "xx";
                session.PlantID = "xxx";
                
                var baqR = Ice.Lib.Framework.WCFServiceSupport.CreateImpl<Ice.Proxy.Rpt.BAQReportImpl>(session, Epicor.ServiceModel.Channels.ImplBase.GetUriPath(typeof(BAQReportSvcContract)));

                var reportID = "xxx";


                var baqRepDS = baqR.GetNewBAQReportParam(reportID);


                baqR.GetDefaults(baqRepDS);

                //baqR.GetNewBAQReportParam("reportid");

                Ice.Rpt.BAQReportDataSet.BAQReportParamRow paramBAQ = baqRepDS.BAQReportParam[0];

                paramBAQ.BAQID = "baq";
                paramBAQ.ReportID = "reportid";
                paramBAQ.ReportTitle = "Report";
                paramBAQ.BAQRptID = "reportid";
                paramBAQ.AutoAction = "SSRSClientPrint";
                paramBAQ.PrinterName = "Microsoft XPS Document Writer";
                paramBAQ.AgentID = "SystemTaskAgent";
                paramBAQ.ReportStyleNum = 1;
                paramBAQ.RptPageSettings = "Color=True,Landscape=False,AutoRotate=False,PaperSize=[Kind=\"Letter\" PaperName=\"Letter\" Height=1100 Width=850],PaperSource=[SourceName=\"Auto Tray Select\" Kind=\"AutomaticFeed\"],PrinterResolution=[Kind=\"Custom\" X=600 Y=600]";
                paramBAQ.RptPrinterSettings = "PrinterName=\"Microsoft XPS Document Writer\",Copies=1,Collate=False,Duplex=Simplex,FromPage=1,ToPage=0";
                paramBAQ.WorkstationID = System.Net.Dns.GetHostName() + " " + Process.GetCurrentProcess().SessionId;
                //paramBAQ.Filter2 = "000035";
                paramBAQ.SSRSRenderFormat = "PDF";
               

                DynamicReportAdapter dynRpt = new DynamicReportAdapter(oTrans);
                dynRpt.BOConnect();

                //dynRpt.GetNewBAQReport();

                dynRpt.GetByID("ProdFormSheet");

                dynRpt.DynamicReportData.BAQRptFilter[0].FilterValue = "000035" ;


                //StringWriter writer = new StringWriter();
                //dynRpt.DynamicReportData.WriteXml(writer);
                paramBAQ.Filter1 = dynRpt.DynamicReportData.GetXml();  //writer.ToString();


                //baqR.RunDirect(baqRepDS);

                baqR.SubmitToAgent(baqRepDS, "SystemTaskAgent",0,0, "Ice.UIRpt.BAQReport;ProdFormSheet");

                dynRpt.Dispose();
            }