Adding to Time Phase grid

I want to add 3 columns to the Time Phase grid (the part number for the Job, the Job quantity and the week commencing of the Job Start Date). We had this working in V8 and I have been looking at the best way to do this in E10. I believe my options are:

  • Carry over the VB code and change references or re-write in C# to add specific columns to grid. However, I believe this is not the most efficient way?

  • Use a BAQ - I found this but believe it is replacing the grid with a BAQ and am not sure it is possible to re-create the Time Phase in a BAQ?
    https://epiusers.help/t/efficiently-adding-column-to-datagrid/36283

  • Or is it possible to add individual columns from a BAQ to an existing grid? I haven’t found any sample code for this so wasn’t sure if it was possible? If so, does anyone have any sample code from any form?

Any advise appreciated :slight_smile:

This should give you a idea on how to accomplish…
use the Wizards - Form Event Wizards to add an EpiViewNotification for the TimePhas View

In the InitializeCustomCode () section, add the code to add your custom columns

if (!(edvTimePhas.dataView.Table.Columns.Contains("ParentPart"))) 
		{
			edvTimePhas.dataView.Table.Columns.Add(new DataColumn("ParentPart"));
			edvTimePhas.dataView.Table.Columns["ParentPart"].ExtendedProperties["ReadOnly"] = true;
		}
		if (!(edvTimePhas.dataView.Table.Columns.Contains("StartDate"))) 
		{
			edvTimePhas.dataView.Table.Columns.Add(new DataColumn("StartDate"));
			edvTimePhas.dataView.Table.Columns["StartDate"].ExtendedProperties["ReadOnly"] = true;
		}

In the script editor, make sure it is looking at the Initialize event
if ((args.NotifyType == EpiTransaction.NotifyType.Initialize))

then

                        if ((args.Row > -1))
			{
        			foreach (DataRowView drV in edvTimePhas.dataView) 
				{
					DataRow dr = drV.Row;	
        				string parentPart = new string();
					string startDate = new string();
					if (string.IsNullOrEmpty(Convert.ToString(dr["JobNum"])) == false) 
					{
        					bool recordSelected;
        					bool showSearch = false;
        					string whereClause = "JobNum = '" + job + "'";
        					DataSet dsJobInfo = SearchFunctions.listLookup(TimePhasForm, "JobAsmSearchAdapter",out recordSelected, showSearch, whereClause);
        					if (recordSelected) 
						{
							parentPart = dsJobInfo.Tables[0].Rows[0]["PartNum"].ToString();
							startDate = ((DateTime)dsJobInfo.Tables[0].Rows[0]["StartDate"]).ToShortDateString();
        					}
        					else 
						{
							parentPart = "";
							startDate = "";
        					}
            				}
                			dr["ParentPart"] = parentPart;
					dr["StartDate"] = startDate;
				}
			}
2 Likes

Thank you. I have entered your code and have the following

----------errors and warnings------------

Error: CS1729 - line 85 (172) - ‘string’ does not contain a constructor that takes 0 arguments
Error: CS1729 - line 86 (173) - ‘string’ does not contain a constructor that takes 0 arguments
Error: CS0103 - line 91 (178) - The name ‘job’ does not exist in the current context

That’s what happens when you only select portions of code :roll_eyes:
replace job with dr[“JobNum”].ToString()
and instead of new string() just use
string parentPart = String.Empty;
string startDate = String.Empty;

I really appreciate your help. I have a ton of (mostly small) customisations to work through and am learning as I go. Unfortunately, although the code compiles the grid shows no data in the 2 added columns. This is my full code:

// **************************************************
// Custom code for TimePhasForm
// Created: 13/03/2019 11:20:25
// **************************************************

extern alias Erp_Contracts_BO_PartPlantSearch;
extern alias Erp_Contracts_BO_Part;

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;

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

	private EpiDataView edvTimePhas;
	// End Wizard Added Module Level Variables **

	// Add Custom Module Level Variables Here **

	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

		this.edvTimePhas = ((EpiDataView)(this.oTrans.EpiDataViews["TimePhas"]));
		this.edvTimePhas.EpiViewNotification += new EpiViewNotification(this.edvTimePhas_EpiViewNotification);
if (!(edvTimePhas.dataView.Table.Columns.Contains("ParentPart"))) 
		{
			edvTimePhas.dataView.Table.Columns.Add(new DataColumn("ParentPart"));
			edvTimePhas.dataView.Table.Columns["ParentPart"].ExtendedProperties["ReadOnly"] = true;
		}
		if (!(edvTimePhas.dataView.Table.Columns.Contains("StartDate"))) 
		{
			edvTimePhas.dataView.Table.Columns.Add(new DataColumn("StartDate"));
			edvTimePhas.dataView.Table.Columns["StartDate"].ExtendedProperties["ReadOnly"] = true;
		}
		// End Wizard Added Custom Method Calls
	}

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

		this.edvTimePhas.EpiViewNotification -= new EpiViewNotification(this.edvTimePhas_EpiViewNotification);
		this.edvTimePhas = null;
		// End Wizard Added Object Disposal

		// Begin Custom Code Disposal

		// End Custom Code Disposal
	}

	private void edvTimePhas_EpiViewNotification(EpiDataView view, EpiNotifyArgs args)
	{
		// ** Argument Properties and Uses **
		// view.dataView[args.Row]["FieldName"]
		// args.Row, args.Column, args.Sender, args.NotifyType
		// NotifyType.Initialize, NotifyType.AddRow, NotifyType.DeleteRow, NotifyType.InitLastView, NotifyType.InitAndResetTreeNodes
		if ((args.NotifyType == EpiTransaction.NotifyType.AddRow))
		{
 if ((args.Row > -1))
			{
        			foreach (DataRowView drV in edvTimePhas.dataView) 
				{
					DataRow dr = drV.Row;	
        				string parentPart = String.Empty;
					string startDate = String.Empty;
					if (string.IsNullOrEmpty(Convert.ToString(dr["JobNum"])) == false) 
					{
        					bool recordSelected;
        					bool showSearch = false;
        					string whereClause = "JobNum = '" + dr["JobNum"].ToString() + "'";
        					DataSet dsJobInfo = SearchFunctions.listLookup(TimePhasForm, "JobAsmSearchAdapter",out recordSelected, showSearch, whereClause);
        					if (recordSelected) 
						{
							parentPart = dsJobInfo.Tables[0].Rows[0]["PartNum"].ToString();
							startDate = ((DateTime)dsJobInfo.Tables[0].Rows[0]["StartDate"]).ToShortDateString();
        					}
        					else 
						{
							parentPart = "";
							startDate = "";
        					}
            				}
                			dr["ParentPart"] = parentPart;
					dr["StartDate"] = startDate;
				}
			}
			{
			}
		}
	}
}
2 Likes

Change “AddRow” to “Initialize” in the epi view notification event handler…

1 Like

Fantastic - thank you so much!

hello, i appreciate this page is quite old but i need similar help adding a column to a grid…
I am using epicor 9.05.701

I would like to add the field JobHead.AnalysisCode to the 2 grids marked with an X in job manager…could anybody give me a complete idiot’s guide on how to do this?
Many thanks.