Add Fields to Epicor Custom Grid

Hi all
@hkeric.wci,
could any one help on this code issue ???
i am trying to apply this code to add a field (OrderRel.NeedByDate) to the Demand Custom Grid in Job Manager, the new issue in this case is passing three parameters not one i.e. OrderNum, OrderLine, and OrderRel, also could you please shed some light on GetByID LINQ structure here, as i menstioned before i have started teach myself C# in the past 6 months, and i am doing OK so far, so if you or any one on this great Forum know useful websites/documents/training material describing using Database C#.Net commands, i will be very appreciated to your advice,

I tried this code and it is giving me a null reference exception. Help.

it is an old post Chris, this issue has been resolved in many ways, check this post mate

OK, not getting the exception anymore but i can’t get this code to work
if (!string.IsNullOrEmpty(resource))
{
DataSet ds = _boReader.GetRows(“Erp:BO:Resource”, “ResourceID=’” + resource + “’”, “Description”);
if(ds.Tables[0].Rows.Count > 0)
{
row.Cells[“ResouceDesc”].Value = ds.Tables[0].Rows[0][“Description”];
}

I am trying to do this on the work queue.

Got this to work. It helps a lot if I spell thing correctly.

i prefer to use a dynamic query over BoReader, it is faster and easier, plenty of examples on the forum, this is one

1 Like

I use Dynamic Query when I need special data or when there exists possibility that a BSA will ask for different filtering.

I prefix the BAQs I use in Code with CODE-MyBAQIntent like CODE-GetLateAPInvoices.

I use BO Reader when its a flat file such as just get me a field from Customer, UDCode, Company Setting… Less dependencies.

2 Likes

many thanks @hkeric.wci
BO Reader (Get Rows) is very slow in the example i tried and posted, may be i need to optimise my code a bit

The nice thing about BOReader is that you can specify in the third arg/param what columns you want returned which in theory should speed it up :thinking:

Hi @tkoch
could you share a full example here please, mine on this thread was selected for one column as a parameter and was very slow compared to the Dynamic query

I was just indicating that in theory since you are specifying a smaller dataset to return boreader should be good to use, though I have not compared it returning the same data vs dynamic query. I have used boreader in a lot of places and haven’t observed any noticeable performance losses. I’ll run a test since I’m now curious

1 Like

I am seeing BOReader is about 4-5 times faster with this test

                Stopwatch stopWatch = new Stopwatch();

                stopWatch.Start();
                DynamicQueryImpl qry = WCFServiceSupport.CreateImpl<DynamicQueryImpl>(epiSession, DynamicQueryImpl.UriPath);
                DynamicQueryDataSet qDs = qry.GetByID("boreadertest");
                QueryExecutionDataSet qed = new QueryExecutionDataSet();

                qDs.QueryWhereItem[0].RValue = "419";

                qDs.AcceptChanges();

                var baqRes = qry.Execute(qDs, qed);
                stopWatch.Stop();
                Debug.WriteLine("DYNAMIC QUERY: " + stopWatch.ElapsedMilliseconds.ToString() + "ms");

                stopWatch.Reset();

                stopWatch.Start();
                BOReaderImpl boReader = WCFServiceSupport.CreateImpl<BOReaderImpl>(epiSession, BOReaderImpl.UriPath);
                string whereClause = "ResourceID='419'";
                DataSet ds = boReader.GetList("Erp:BO:Resource", whereClause, "Description");
                stopWatch.Stop();
                Debug.WriteLine("BOREADER: " + stopWatch.ElapsedMilliseconds.ToString() + "ms"); 
1 Like

you are using GetList, would GetRows to grid could make a different ?

Good call, let me try that

Still similar results

then based on this, the second step which is inserting back the data to existed grid row by row is the bottleneck as DQ will display the whole data in one hit !! am i right ?

Yes, I think it is slow because it runs for each row in the grid. I have done in the past if I know I need data like this I just pull all the data in one call to a dataset (just query for Resource table on form load) then on row initialize find the relevant data in the dataset rather than running a query for each row

1 Like

sharing your example here will be priceless :grin:

I’ll have to locate it, been awhile

This is an example of me hijacking the grid on Part Trans History Tracker and adding columns using BAQDataView. Made it run much quicker than per grid row queries

// **************************************************
// Custom code for PartTranHistForm
// Created: 5/28/2015 5:19:45 PM
// **************************************************

extern alias Erp_Contracts_BO_Part;
extern alias Erp_Contracts_BO_PartPlantSearch;

using System;
//using System.Linq;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Windows.Forms;
using Erp.UI;
using Ice.Lib.Customization;
using Ice.Lib.ExtendedProps;
using Ice.Lib.Framework;
using Ice.Lib.Searches;
using Ice.UI.FormFunctions;
using Epicor.ServiceModel.Channels;
using Ice.Proxy.Lib;
using Ice.Core;
using System.Data.SqlClient;
using Ice.Lib.Broadcast;

public class Script
{
	// ** Wizard Insert Location - Do Not Remove 'Begin/End Wizard Added Module Level Variables' Comments! **
	// Begin Wizard Added Module Level Variables **

	// End Wizard Added Module Level Variables **

	// Add Custom Module Level Variables Here **
	private EpiDataView edvTranJobInfo;
	private EpiUltraGrid dgv;
	private EpiButton btnRet;

	public void InitializeCustomCode()
	{
		// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Variable Initialization' lines **
		// Begin Wizard Added Variable Initialization

		// End Wizard Added Variable Initialization

		// Begin Wizard Added Custom Method Calls

		// End Wizard Added Custom Method Calls
		dgv = (EpiUltraGrid)csm.GetNativeControlReference("f83d6262-a7d9-4fb5-a7d0-54644a9bb66b");
		btnRet = (EpiButton)csm.GetNativeControlReference("e0aaf31e-51a0-4692-8932-9ff0545e716e");
		btnRet.Click += btnRet_Click;

		CreateBAQView();		
	}

	public void DestroyCustomCode()
	{
		// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Object Disposal' lines **
		// Begin Wizard Added Object Disposal

		// End Wizard Added Object Disposal

		// Begin Custom Code Disposal
		btnRet.Click -= btnRet_Click;
		btnRet = null;
		dgv = null;
		edvTranJobInfo = null;
		// End Custom Code Disposal
	}

	private void btnRet_Click(object sender, System.EventArgs e)
	{
				DataView dv = dgv.DataSource as DataView;
				if (!dv.Table.Columns.Contains("AsmSeq"))				
					dv.Table.Columns.Add("AsmSeq");
				
				if (!dv.Table.Columns.Contains("JobSeq"))				
					dv.Table.Columns.Add("JobSeq");
				
				if (!dv.Table.Columns.Contains("JobDesc"))
					dv.Table.Columns.Add("JobDesc");
				if (!dv.Table.Columns.Contains("EmpId"))
					dv.Table.Columns.Add("EmpId");
				if (!dv.Table.Columns.Contains("EmpName"))
					dv.Table.Columns.Add("EmpName");
				
				
				foreach (DataRow row in dv.Table.Rows)
				{
					foreach (DataRow row2 in edvTranJobInfo.dataView.Table.Rows)
					{
						if (row["TranNum"].ToString() == row2["PartTran_TranNum"].ToString())
						{
							row["AsmSeq"] = row2["PartTran_AssemblySeq"];
							row["JobSeq"] = row2["PartTran_JobSeq"];
							row["JobDesc"] = row2["JobHead_PartDescription"];
							row["EmpId"] = row2["EmpBasic_EmpId"];
							row["EmpName"] = row2["EmpBasic_Name"];
							break;
						}
					}
				}
		
				dgv.DataSource = dv;		
	}

	// this is needed to speed up loading of records
	private void CreateBAQView()
	{
		BAQDataView baqView = new BAQDataView("PartTranJobInfo");
		oTrans.Add("PartTranJobInfo", baqView);
		string pubBinding = "Part.PartNum";
		//string plantBinding = "PartTranHist.Plant";
		IPublisher pub = oTrans.GetPublisher(pubBinding);
		if (pub == null)
		{
			oTrans.PublishColumnChange(pubBinding, "PartNumPub");
			pub = oTrans.GetPublisher(pubBinding);	 
		}
		
		//subscribe to BAQView
		if (pub != null)
		{
			baqView.SubscribeToPublisher(pub.PublishName, "PartTran_PartNum");
		}

		edvTranJobInfo = (EpiDataView)oTrans.EpiDataViews["PartTranJobInfo"];
	}
}
1 Like