hasokeric
8/11/2016 - 3:33 AM

Epicor 10.1 Call BAQ From Code

Epicor 10.1 Call BAQ From Code

	// Execute a BAQ by Calling the Business Object via WCF
	private void CallBAQUsingBO()
	{
		try
		{
			// Declare and Initialize Variables
			string BAQName = "DIEN-HASO";
			Ice.BO.QueryExecutionDataSet ds = new Ice.BO.QueryExecutionDataSet();
	
			// Add Parameter Rows
			// Definition: AddExecutionParameterRow(string ParameterID, string ParameterValue, string ValueType, bool IsEmpty, Guid SysRowID, string RowMod)
			// Possible ValueTypes: nvarchar, int, decimal, date, datetime, bit, uniqueidentifier, bigint
			// IsEmpty indicates if your passed value Is Empty because if it is, you can define in your params to use a default value if empty.
			// Typically you use string.IsNullOrEmpty(yourValueVariable) but if you are hard coding a value then you can simply set it to false
			ds.ExecutionParameter.AddExecutionParameterRow("QuoteNumber", "10003", "int", false, Guid.Empty, "A");
			ds.ExecutionParameter.AddExecutionParameterRow("FirstName", "Bill", "nvarchar", false, Guid.Empty, "A");
	
			// Use Business Object Directly
			Ice.Proxy.BO.DynamicQueryImpl dynamicQuery = WCFServiceSupport.CreateImpl<Ice.Proxy.BO.DynamicQueryImpl>((Ice.Core.Session)oTrans.Session, Epicor.ServiceModel.Channels.ImplBase<Ice.Contracts.DynamicQuerySvcContract>.UriPath);
			System.Data.DataSet results = dynamicQuery.ExecuteByID(BAQName, ds);
	
			// Lets Loop through our results
			if (results.Tables["Results"].Rows.Count > 0)
			{
				foreach (DataRow item in results.Tables["Results"].Rows)
				{
					// In E9 you used TableName.Column in E10 it is TableName_Column
				    string val = item["QuoteHed_QuoteNum"].ToString();
				}
			}
		} catch (System.Exception ex)
		{
			ExceptionBox.Show(ex);
		}
	}


	// Execute a BAQ by Calling the Client Adapter
	private void CallBAQUsingAdapter()
	{
		try
		{
			// Declare and create an instance of the Adapter.
			DynamicQueryAdapter adapterDynamicQuery = new DynamicQueryAdapter(this.oTrans);
			adapterDynamicQuery.BOConnect();

			// Declare and Initialize Variables
			string BAQName = "DIEN-HASO";
			Ice.BO.QueryExecutionDataSet ds = new Ice.BO.QueryExecutionDataSet();

			// Add Parameter Rows
			// Definition: AddExecutionParameterRow(string ParameterID, string ParameterValue, string ValueType, bool IsEmpty, Guid SysRowID, string RowMod)
			// Possible ValueTypes: nvarchar, int, decimal, date, datetime, bit, uniqueidentifier, bigint
			// IsEmpty indicates if your passed value Is Empty because if it is, you can define in your params to use a default value if empty.
			// Typically you use string.IsNullOrEmpty(yourValueVariable) but if you are hard coding a value then you can simply set it to false
			ds.ExecutionParameter.AddExecutionParameterRow("QuoteNumber", "10003", "int", false, Guid.Empty, "A");
			ds.ExecutionParameter.AddExecutionParameterRow("FirstName", "Bill", "nvarchar", false, Guid.Empty, "A");

			// Call Adapter method
			adapterDynamicQuery.ExecuteByID(BAQName, ds);

			// Lets Loop through our results
			if (adapterDynamicQuery.QueryResults.Tables["Results"].Rows.Count > 0)
			{
				foreach (DataRow item in adapterDynamicQuery.QueryResults.Tables["Results"].Rows)
				{
					// In E9 you used TableName.Column in E10 it is TableName_Column
				    string val = item["QuoteHed_QuoteNum"].ToString();
				}
			}

			// Cleanup Adapter Reference
			adapterDynamicQuery.Dispose();

		} catch (System.Exception ex)
		{
			ExceptionBox.Show(ex);
		}
	}