Updating UD field in SugPoDtl table with the PartDtl.SourceFile Data

I have recently started learning development in Epicor and I am trying to update the the UD field SugPoDtl.Source_c with the PartDtl.SourceFile Data so that the Source_c field will show the data of SourceFile in the Material List grid of New PO Suggestions menu. Please assist.

Below are the code I am using but doesn’t seem to be working. Since I was not able to add any control from Event Wizard to the base grid. I have created a custom grid epiUltraGridC1

using System;
using System.Data;
using System.Windows.Forms;
using Erp.Adapters;
using Ice.Lib.Framework;

public class Script
{
	// Add Custom Module Level Variables Here
	private EpiDataView edvSugPoDtl;
	private EpiDataView edvPartDtl;

	public void InitializeCustomCode()
	{
		// Initialize EpiDataViews for SugPoDtl and PartDtl
		edvSugPoDtl = (EpiDataView)oTrans.EpiDataViews["SugPoDtl"];
		edvPartDtl = (EpiDataView)oTrans.EpiDataViews["PartDtl"];
	this.epiUltraGridC1.InitializeRow += new Infragistics.Win.UltraWinGrid.InitializeRowEventHandler(this.epiUltraGridC1_InitializeRow);

	}

	public void DestroyCustomCode()
	{
		this.epiUltraGridC1.InitializeRow -= new Infragistics.Win.UltraWinGrid.InitializeRowEventHandler(this.epiUltraGridC1_InitializeRow);
	}



	private void epiUltraGridC1_InitializeRow(object sender, Infragistics.Win.UltraWinGrid.InitializeRowEventArgs args)
	{
		// ** Place Event Handling Code Here **

		if (edvSugPoDtl != null && edvSugPoDtl.HasRow && edvPartDtl != null && edvPartDtl.HasRow)
		{
			// Update SugPoDtl.Source_c with PartDtl.SourceFile
			UpdateField(edvSugPoDtl, "Source_c", edvPartDtl, "SourceFile");

			// Update SugPoDtl.InventoryQty_c with PartDtl.InvtyQty
			UpdateField(edvSugPoDtl, "InventoryQty_c", edvPartDtl, "InvtyQty");

			// Notify that the data has been changed
			edvSugPoDtl.Notify(new EpiNotifyArgs(oTrans, edvSugPoDtl.Row, EpiTransaction.NotifyType.Initialize));

			// Refresh the grid to reflect the changes in the UI
			RefreshGrid();
	}
}


	/*private void epiUltraGridC1_BeforeRowUpdate(object sender, Infragistics.Win.UltraWinGrid.CancelableRowEventArgs args)
	{
		// ** Place Event Handling Code Here **

		if (edvSugPoDtl != null && edvSugPoDtl.HasRow && edvPartDtl != null && edvPartDtl.HasRow)
		{
			// Update SugPoDtl.Source_c with PartDtl.SourceFile
			UpdateField(edvSugPoDtl, "Source_c", edvPartDtl, "SourceFile");

			// Update SugPoDtl.InventoryQty_c with PartDtl.InvtyQty
			UpdateField(edvSugPoDtl, "InventoryQty_c", edvPartDtl, "InvtyQty");

			// Notify that the data has been changed
			edvSugPoDtl.Notify(new EpiNotifyArgs(oTrans, edvSugPoDtl.Row, EpiTransaction.NotifyType.Initialize));

			// Refresh the grid to reflect the changes in the UI
			RefreshGrid();
		}
	}*/

	private void UpdateField(EpiDataView targetView, string targetField, EpiDataView sourceView, string sourceField)
	{
		// Check if the field exists before updating
		if (targetView.dataView.Table.Columns.Contains(targetField) && sourceView.dataView.Table.Columns.Contains(sourceField))
		{
			targetView.dataView[targetView.Row][targetField] = sourceView.dataView[sourceView.Row][sourceField];
		}
	}

	private void RefreshGrid()
	{
		// Assuming the grid is bound to the SugPoDtl data view, force a refresh
		// Ensure the grid is updated to reflect changes
		EpiUltraGrid grid = (EpiUltraGrid)csm.GetNativeControlReference("4d59326f-7a76-4c5c-8e2c-54e630db64da"); // Assuming this is the grid reference
		if (grid != null)
		{
			grid.DataSource = edvSugPoDtl.dataView;
			grid.Refresh();
		}
	}

}

I am not seeing any obvious problems. Maybe try creating a textbox off to the side of the UI bound to the fields you are working with just to confirm that they are updating as you expect. Sometimes the grid doesn’t behave intuitively. Have you verified that the InitializeRow event is firing when you are expecting it to and that the values in your IF statement are all evaluating to true? I’d break it down into smaller chunks to test that each “piece” is working as you’d expect.

Hi Dan, thanks for responding back. I did add the field on the Detail tab to check if the data is getting populated but in vain. It shows the same value as grid which is blank.
Could you please assist further? I did test the code few times and it is valid but I am not sure how to test if the InitializeRow Event is firing. Could you please assist?

My “go-to” is to add something like this to my code inside of the InitializeRow code block.

 MessageBox.Show("I am initializing the row");

You should get a pop-up message when the row is initialized. If you don’t get the message box, then you know that event is not firing.

Hi Dan,

I am able to see the pop up on my screen. What might be the problem of data not getting updated into the fields? What other checks can I do?

I’d just continue to break it into smaller pieces and see what’s working and what’s not. Maybe try your UpdateField using a button click so you can ensure it’s firing. If it works with a button click, you know it’s good and you just have to figure out why it’s not working inside the InitializeRow event. If it’s not working on a button click, then you can try to understand why. Or you could add another message box inside your if statement within the InitializeRow code block and have it display something from the EDVs that you’re using below. Maybe make sure that the values are present at the time the event is firing. Make sure that all the conditions in the if statement are evaluating to true. It’s all about just breaking it down into smaller pieces in order to find the part that’s not working (or multiple parts).