C# Help with DynamicCriteria Report

Hi

I’ve got the following code working, by taking examples from the forum and then using BL Tester and looking at the .dll to work out the relevant method calls and properties. It works, but it’s not dynamic because I can’t work out the XML bit for UserCriteria.

Working Code - but static
private void RunCOAReport(string orderNum)
	{
		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))
			{
				aSA.BOConnect();
				aSA.GetDefaultTaskAgentID(out agentID);
				if(!string.IsNullOrEmpty(agentID))
				{
					agentID = "SystemTaskAgent";
				}
			}
	
			//MessageBox.Show(agentID + ", " + workStation);
	
			var dynamicCriteriaReport = WCFServiceSupport.CreateImpl<Ice.Proxy.Rpt.DynamicCriteriaImpl>((Session)oTrans.Session, Epicor.ServiceModel.Channels.ImplBase<Ice.Contracts.DynamicCriteriaSvcContract>.UriPath);
						
			var rptParams = dynamicCriteriaReport.GetNewDynamicCriteriaReportParam("COAReport");
										
			rptParams.DynamicCriteriaParam[0].AutoAction = "SSRSPREVIEW";
			rptParams.DynamicCriteriaParam[0].ReportStyleNum = 1002;
			rptParams.DynamicCriteriaParam[0].WorkstationID = workStation;
			rptParams.DynamicCriteriaParam[0].SSRSRenderFormat = "PDF";
			rptParams.DynamicCriteriaParam[0].SSRSEnableRouting = false;
			rptParams.DynamicCriteriaParam[0].UserCriteria = @"<?xml version=""1.0"" encoding=""utf-8"" standalone=""yes""?> <UICriteria><RptCriteriaSet><Company /><RptDefID>COAReport</RptDefID><RptCriteriaSetID>COAReport</RptCriteriaSetID><Description>COA Report</Description></RptCriteriaSet><RptCriteriaPrompt><PromptID>1</PromptID><PromptValue>168436</PromptValue><IsToken>false</IsToken><PromptName>OrderNumFrom</PromptName><DataType>int</DataType><Label>Order (From)</Label></RptCriteriaPrompt><RptCriteriaPrompt><PromptID>2</PromptID><PromptValue>168436</PromptValue><IsToken>false</IsToken><PromptName>OrderNumTo</PromptName><DataType>int</DataType><Label>Order (To)</Label></RptCriteriaPrompt><RptCriteriaPrompt><PromptID>3</PromptID><PromptValue>2021-03-11T00:00:00</PromptValue><IsToken>false</IsToken><PromptName>ShipDateFrom</PromptName><DataType>datetime</DataType><Label>Ship Date (From)</Label></RptCriteriaPrompt><RptCriteriaPrompt><PromptID>4</PromptID><PromptValue>2021-03-11T00:00:00</PromptValue><IsToken>false</IsToken><PromptName>ShipDateTo</PromptName><DataType>datetime</DataType><Label>Ship Date (To)</Label></RptCriteriaPrompt> </UICriteria>";
			
			rptParams.AcceptChanges();

			dynamicCriteriaReport.RunDirect(rptParams);			
	
		}
		catch (Exception ex)
		{
			MessageBox.Show("An error occured trying to print report." + ex.Message);		
		}
	
	}

I’ve seen other code posted by @josecgomez that uses .WriteXML() method, but that seems to be for another report type.

Am I correct in thinking there are at least 3 different report types:

  1. Standard Reports (each of which have their own reporting DLL)
  2. BAQ Reports
  3. Dynamic Criteria Reports

I haven’t found any examples of people using C# to call Dynamic Criteria reports, so hopefully once my code is complete and working I’ll post the final version!

Thanks!

I have code working that runs a dynamic query report and submits it to the agent and emails it. In my case I had to build the string with a foreach statement because I was passing multiple values to a filter parameter.

In your case it should be easier, since they are all prompts.
One method would be something like this:

String.Format("<?xml version=""1.0"" encoding=""utf-8"" standalone=""yes""?> <UICriteria><RptCriteriaSet><Company /><RptDefID>COAReport</RptDefID><RptCriteriaSetID>COAReport</RptCriteriaSetID><Description>COA Report</Description></RptCriteriaSet><RptCriteriaPrompt><PromptID>1</PromptID><PromptValue>{0}</PromptValue><IsToken>false</IsToken><PromptName>OrderNumFrom</PromptName><DataType>int</DataType><Label>Order (From)</Label></RptCriteriaPrompt><RptCriteriaPrompt><PromptID>2</PromptID><PromptValue>{1}</PromptValue><IsToken>false</IsToken><PromptName>OrderNumTo</PromptName><DataType>int</DataType><Label>Order (To)</Label></RptCriteriaPrompt><RptCriteriaPrompt><PromptID>3</PromptID><PromptValue>{2}</PromptValue><IsToken>false</IsToken><PromptName>ShipDateFrom</PromptName><DataType>datetime</DataType><Label>Ship Date (From)</Label></RptCriteriaPrompt><RptCriteriaPrompt><PromptID>4</PromptID><PromptValue>{3}</PromptValue><IsToken>false</IsToken><PromptName>ShipDateTo</PromptName><DataType>datetime</DataType><Label>Ship Date (To)</Label></RptCriteriaPrompt> </UICriteria>", orderNumFrom.ToString(), orderNumTo.ToString(), shipDateFrom.ToString(), shipDateTo.ToString())

Replace the orderNumFrom, orderNumTo, shipDateFrom and shipDateTo with your variables for each.

Ah thanks Joseph! It was late the other night when I posted, didn’t even think of using String format!

I have now moved it on a bit, and will be passing in multiple OrderNum values to a parameter list. That leads me to need to do a foreach loop like you hinted at, so thanks for making the suggestions to keep me moving forward.