I’m sure this has been asked on here before but I can’t find it. We are going away from Crystal Reports and now I have a new SSRS report that was developed. I want to print it directly from my C# customization code on demand. Do any of you have any guidance or instructions on how to do that?
@Joel_Bailie , Please use the below mentioned code
private void epiButtonC1_Click(object sender, System.EventArgs args)
{
string agentID = "";
try
{
Session otSession = (Session)oTrans.Session;
//Set the workstationID
string workStation = Ice.Lib.Report.EpiReportFunctions.GetWorkStationID(otSession);
//Get or Set the AgentID
using (var aSA = new SysAgentAdapter(oTrans))
{
oTrans.PushStatusText("Get System Agent Info", true);
aSA.BOConnect();
aSA.GetDefaultTaskAgentID(out agentID);
if (!string.IsNullOrEmpty(agentID)) { agentID = "SystemTaskAgent"; }
}
{
var baqR = WCFServiceSupport.CreateImpl<Ice.Proxy.Rpt.BAQReportImpl>((Session)oTrans.Session, Epicor.ServiceModel.Channels.ImplBase<Ice.Contracts.BAQReportSvcContract>.UriPath);
var dynamicReport = WCFServiceSupport.CreateImpl<Ice.Proxy.BO.DynamicReportImpl>((Session)oTrans.Session, 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("P-NOTES2");
var baqRptDS = baqR.GetNewBAQReportParam("P-NOTES2");
//baqRptDS.BAQReportParam[0].Option01 = guid.ToString();
baqRptDS.BAQReportParam[0].AutoAction="SSRSPrint";
baqRptDS.BAQReportParam[0].PrinterName=@"\\server1\BrotherEngineering";
baqRptDS.BAQReportParam[0].RptPageSettings = "Color=False,Landscape=True,Margins=[Left=0 Right=0 Top=0 Bottom=0],PaperSize=[Kind='Letter' PaperName='Letter' Height=1100 Width=850],PaperSource=[SourceName='Auto Select' Kind='AutomaticFeed'],PrinterResolution=[Kind='Custom' X=600 Y=600]";
baqRptDS.BAQReportParam[0].RptPrinterSettings = "PrinterName='\\\\server1\\BrotherEngineering',Copies=1,Collate=False,Duplex=Simplex,FromPage=1,ToPage=1";
baqRptDS.BAQReportParam[0].PrintReportParameters=false;
baqRptDS.BAQReportParam[0].WorkstationID=workStation;
baqRptDS.BAQReportParam[0].SSRSRenderFormat = "PDF";
baqRptDS.BAQReportParam[0].Character01="PrintPrev";
//baqRptDS.BAQReportParam[0].Character02=flag;
baqRptDS.BAQReportParam[0].BAQRptID=("P-NOTES2");
baqRptDS.BAQReportParam[0].ReportID=("P-NOTES2");
baqRptDS.BAQReportParam[0].Summary = false;
baqRptDS.BAQReportParam[0].ReportStyleNum = 1;
baqRptDS.BAQReportParam[0].BAQID=("P-NOTES2");
baqRptDS.BAQReportParam[0].ReportTitle = "Production Notes";
//baqRptDS.BAQReportParam[0].TaskNote = guid.ToString();
//rptDs.BAQRptOptionFld[0].FieldValue = guid.ToString();
rptDs.AcceptChanges();
StringWriter writer = new StringWriter();
rptDs.WriteXml(writer);
baqRptDS.BAQReportParam[0].Filter1 = writer.ToString();
//baqR.RunDirect(baqRptDS);
baqR.SubmitToAgent(baqRptDS, agentID, 0, 0, "Epicor.Mfg.UIRpt.BAQReport");
}
}
catch (Exception ex)
{
MessageBox.Show("An error occured trying to print report." + ex.Message);
}
}
1 Like
Thank you. I will try this.
1 Like
Just tackled this one myself. There’s other versions floating around (which we of great help in getting me started) but are a bit more elaborate than they have to be. Example, a lot of examples save changes to the DynamicReport object, but that item is only used to fill a filter field in the BAQReport object with XML and is then discarded. I tried to strip this down as much as possible.
This example also passes a key value into the report to pull only the current item.
if (UD03_Row.HasRow)
{
var session = (Ice.Core.Session)oTrans.Session;
string uri = Epicor.ServiceModel.Channels.ImplBase<Ice.Contracts.BAQReportSvcContract>.UriPath;
string agent;
string reportName = "CorrectiveActs";
var writer = new System.IO.StringWriter();
//Needed to submit the report to the correct agent.
using (var agentAdapter = new SysAgentAdapter(oTrans))
{
agentAdapter.BOConnect();
agentAdapter.GetDefaultTaskAgentID(out agent);
}
//Gets BAQ Report defaults, sets key field (equivalent to Option Column in BAQ Report popup)
//Then writes to xml object which is inserted into actual BAQ Report submission in next block.
using (var reportAdapter = new DynamicReportAdapter(oTrans))
{
reportAdapter.BOConnect();
reportAdapter.GetByID(reportName);
var rof = reportAdapter.DynamicReportData.BAQRptOptionFld;
rof[0][rof.FieldValueColumn] = (string)UD03_Row.CurrentDataRow["Key1"];
reportAdapter.DynamicReportData.WriteXml(writer);
}
//Executes the actual BAQ Report. I didn't see an adapter for this, so I used the service.
using (var baqReport = WCFServiceSupport.CreateImpl<Ice.Proxy.Rpt.BAQReportImpl>(session, uri))
{
Ice.Rpt.BAQReportDataSet brds = baqReport.GetNewBAQReportParam(reportName);
var rp = brds.BAQReportParam; //Because 120 chars is my limit.
rp[0][rp.BAQIDColumn] = "Search_CorrectiveActions"; //BAQ Name
rp[0][rp.Filter1Column] = writer; //FromDynamicReport
rp[0][rp.UserIDColumn] = session.UserID; //It's you. Hi, you.
rp[0][rp.BAQRptIDColumn] = reportName; //BAQ Report Name
rp[0][rp.WorkstationIDColumn] = session.TaskClientID; //Client Computer Name
rp[0][rp.AgentIDColumn] = agent; //Not Mr. Anderson.
rp[0][rp.AutoActionColumn] = "SSRSPREVIEW";
rp[0][rp.SSRSRenderFormatColumn] = "PDF";
//oTrans.PushStatusText("Report Submitted", false);
MessageBox.Show("Report Submitted");
baqReport.SubmitToAgent(brds,
rp[0].AgentID,
rp[0].AgentSchedNum,
rp[0].AgentTaskNum,
"Epicor.Mfg.UIRpt.BAQReport");
//oTrans.PushStatusText("Ready", false);
}
}
1 Like
Thank you John. I will use this to compare with what I have and make updates/corrections.