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();
}
}
}