Adding a UD Field to a Grid

All,

OK, so this has been covered seven ways from Sunday, and I think I have reviewed all of the relevant posts and am still stuck.

I have added a UD Field (cBuyerDueDate_c) to the PO Release table (Erp.PORel). I want to add it to the grid views on the Buyer’s Workbench. @josecgomez has a great YouTube video on how do do this by replacing the existing grid bindings with a BAQ result set (thanks Jose!). After replacing three of the PO related grids on the Workbench using this method, I realized that they no longer sync with the Tree View–the user cannot select the PO on the Tree View and have it navigate to the same PO on the grid view. I also discovered that the PO Entry… button no longer opened the selected PO


(Epicor standard functionality)

I figured that I might be able to replace the existing button with a custom button and get that to work with the new grid views, but fixing the tree view appears to be a rabbit hole. I could ask my users to ignore the tree view and use right-click/Open With… and I might resort to that. I thought, however, that I would at least try the other suggested method, which is to create a new column in the grid and use the BOReader assembly reference to populate it on the fly. I realize from the feedback on this site, that this method is inefficient and may have performance issues.

The code compiles and the form loads without error. The column gets added to the grid, but it is not populating.

I think this is the section of the custom code that is not working as intended:

	private void grdLatePOR_InitializeRow(object sender, Infragistics.Win.UltraWinGrid.InitializeRowEventArgs e)
	{
		if(!String.IsNullOrEmpty(e.Row.Cells["PONum"].Value.ToString()) && !String.IsNullOrEmpty(e.Row.Cells["POLine"].Value.ToString()) && !String.IsNullOrEmpty(e.Row.Cells["PORelNum"].Value.ToString()))
		{
		DataSet ds = _boReader.GetRows("Erp:BO:PORel","PONum='" + e.Row.Cells["PONum"].Value.ToString()+ "' and POLine='" + e.Row.Cells["POLine"].Value.ToString()+ "' and PORelNum='" + e.Row.Cells["PORelNum"].Value.ToString() + "'","cBuyerDueDate_c");
		if(ds.Tables[0].Rows.Count > 0 )
			e.Row.Cells["cBuyerDueDate_c"].Value = ds.Tables[0].Rows[0]["cBuyerDueDate_c"];
		}
	
	}

When I debug this in Visual Studio, I get a Null Exception error on the DataSet ds =… line. Because the UD field is a date value, it is NULL in some cases, and I am guessing that I need to handle that in the code–not sure how to do that. It may also be that I am not clear no how to query the data correctly through _boReader.GetRows. I am a C# novice and could use some help on this.

For context, I have added these custom assembly references…

image

…and here is all of my custom code…

using System;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Windows.Forms;
using Erp.Adapters;
using Erp.UI;
using Ice.Lib;
using Ice.Adapters;
using Ice.Lib.Customization;
using Ice.Lib.ExtendedProps;
using Ice.Lib.Framework;
using Ice.Lib.Searches;
using Ice.UI.FormFunctions;

using Ice.Proxy.Lib;
using Ice.Core;
using Ice.Contracts;
using Erp.BO;
using Ice.BO;

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 **
	EpiUltraGrid lateGrid;
	BOReaderImpl _boReader;

	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
		lateGrid = (EpiUltraGrid)csm.GetNativeControlReference("7165b214-eac4-4184-8d1e-3c9770bfc022");
		lateGrid.DisplayLayout.Bands[0].Columns.Add("cBuyerDueDate_c", "Buyer Date");
		lateGrid.InitializeRow += new Infragistics.Win.UltraWinGrid.InitializeRowEventHandler(grdLatePOR_InitializeRow);
		BOReaderImpl _boReader = WCFServiceSupport.CreateImpl<BOReaderImpl>((Ice.Core.Session)oTrans.Session, Epicor.ServiceModel.Channels.ImplBase<Ice.Contracts.BOReaderSvcContract>.UriPath);
	}

	private void grdLatePOR_InitializeRow(object sender, Infragistics.Win.UltraWinGrid.InitializeRowEventArgs e)
	{
		if(!String.IsNullOrEmpty(e.Row.Cells["PONum"].Value.ToString()) && !String.IsNullOrEmpty(e.Row.Cells["POLine"].Value.ToString()) && !String.IsNullOrEmpty(e.Row.Cells["PORelNum"].Value.ToString()))
		{
		DataSet ds = _boReader.GetRows("Erp:BO:PORel","PONum='" + e.Row.Cells["PONum"].Value.ToString()+ "' and POLine='" + e.Row.Cells["POLine"].Value.ToString()+ "' and PORelNum='" + e.Row.Cells["PORelNum"].Value.ToString() + "'","cBuyerDueDate_c");
		if(ds.Tables[0].Rows.Count > 0 )
			e.Row.Cells["cBuyerDueDate_c"].Value = ds.Tables[0].Rows[0]["cBuyerDueDate_c"];
		}
	
	}

	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

		// End Custom Code Disposal
		lateGrid.InitializeRow -= new Infragistics.Win.UltraWinGrid.InitializeRowEventHandler(grdLatePOR_InitializeRow);
		_boReader = null;
	}
}

Thanks in advance for any pointers.

Regards,

Michael Thompson

You can easily fix the tree view sync issue, simply hook onto the EpiViewNotify event of the original TreeView DataView and when that fires or changes, set the Row number of your new grid (dataview) to match that value which is selected in the current tree view.

Doing a lookup with BOReader for each row in the grid will take YEARS… (being exaggerated but its highly inefficient and slow)

Thanks, Jose, while probably not being as easy for us novices, I understand where you are going with this. Perhaps the tree synchronization is easier than I imagined, and the performance of the POReader method even less efficient that I imagined.

I have the EpiViewNotification stubbed into the form, now I just have to figure out how to set the row number on the new dataview. I appreciate your help and will post my final solution once I figure it out.

You could grab the entire list of SysRow ID’s then pass that into one BOReader call and disperse the results to your EDV.

1 Like

‘’’
edvMyView.Row=6

‘’’
You just have to find the right one by looping though the dataview and compare keys

Hi Folks, can anyone let me know where this video can be found? I need to add notes to the “Late/Today/Future…” etc. grids and using a BAQ result looks like it will tick all my boxes.

Thanks, Steve.

Hi @SteveM_Captec
there are many ways to do that, and i do not know if you have read this thread, this might help you to add the field to the UI screen, specially Epicor Tracker dashboard

Thanks Al, I looked at that thread but there is significant code involved and I am no programmer. I have created numerous BAQ’s/Dashboards/Reports etc. and was hoping to be able to change the grid to a BAQ view to make life easier. If that is not a simple option, then it will either have to be put out to a consultant or the user can work with the dashboard that already provides the info he is looking for. It just means he has to have two windows open.
Thanks again,
Steve.

1 Like