Update Bin/Warehouse in Mass Issue via BAQ Dataview Click but it is triggering the Negative Stock Check method

Hi All,

So I am trying to use a BAQ Dataview to show “On Hand Locations” for materials. When the dataview is clicked, the warehouse and bin locations will update to match the dataview.

It has worked successfully on the issue material screen, but on the mass issue material screen whenever I click off of one line to update the next on the material list it triggers the Negative Stock Check method which errors out the mass issue screen and clears all the data.

Below is the current script and image of what it looks like.

// **************************************************
// Custom code for MassIssueForm
// Created: 3/20/2024 8:59:52 AM
// **************************************************

extern alias Erp_Contracts_BO_MassIssueToMfg;
extern alias Erp_Contracts_BO_IssueReturn;
extern alias Erp_Adapters_MassIssuetoMfg;

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.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 **
	BAQDataView onHandLocForIssuingBAQDV;
	int RowNumBAQ;
	int RowNumIssue;
    EpiUltraGrid eugIssueMaterialGrid;

	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
		CreateOnHandLocForIssuingBAQDV();
		eugIssueMaterialGrid = (EpiUltraGrid)csm.GetNativeControlReference("7908565c-cc3c-43d1-b85b-9921ad88fb89");
		this.gridOnHandLoc.Click += new System.EventHandler(this.gridOnHandLoc_Click);

		// 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

		// End Wizard Added Object Disposal
		this.gridOnHandLoc.Click -= new System.EventHandler(this.gridOnHandLoc_Click);
		// Begin Custom Code Disposal

		// End Custom Code Disposal
	}

	public void CreateOnHandLocForIssuingBAQDV()
	{
		onHandLocForIssuingBAQDV = new BAQDataView("OnHandLocForIssuing");
		oTrans.Add("OnHandLocForIssuingBAQDV",onHandLocForIssuingBAQDV); 
		string pub1Binding = "Mtl.PartNum"; 
		IPublisher pub1 = oTrans.GetPublisher(pub1Binding);

		if(pub1==null) 
		{ 
			string pubName = Guid.NewGuid().ToString();
			oTrans.PublishColumnChange(pub1Binding, pubName);
			pub1 = oTrans.GetPublisher(pub1Binding);
		} 
		if(pub1 !=null) 
		{
			onHandLocForIssuingBAQDV.SubscribeToPublisher(pub1.PublishName, "Part_PartNum");
		}
	}



//When BAQ dataview is selected, update the warehouse and bin if not null
	private void gridOnHandLoc_Click(object sender, System.EventArgs args)
	{
		// ** Place Event Handling Code Here **
		//MessageBox.Show ("In Cell Activate");

		RowNumBAQ = -1;
		RowNumIssue = -1;

		//Loop for active line in BAQ grid
		foreach(var rowBAQ in gridOnHandLoc.Rows)
		{
			//MessageBox.Show ("In For Loop");
			RowNumBAQ = RowNumBAQ+1;
			if(rowBAQ.Selected == true)
			{
				//Loop for active line in Issuing Grid
				foreach(var rowIssue in eugIssueMaterialGrid.Rows)
				{
					RowNumIssue = RowNumIssue+1;
					if(rowIssue.Selected == true)
					{
						//MessageBox.Show ("In Selected IF");
						if(gridOnHandLoc.Rows[RowNumBAQ].Cells["PartBin_WarehouseCode"].Value !=null && gridOnHandLoc.Rows[RowNumBAQ].Cells["PartBin_BinNum"].Value !=null) 
						{
							//MessageBox.Show ("In Value Change Area");
			 			   eugIssueMaterialGrid.Rows[RowNumIssue].Cells["Warehouse"].Value = gridOnHandLoc.Rows[RowNumBAQ].Cells["PartBin_WarehouseCode"].Value.ToString();
							eugIssueMaterialGrid.Rows[RowNumIssue].Cells["BinNum"].Value = gridOnHandLoc.Rows[RowNumBAQ].Cells["PartBin_BinNum"].Value.ToString();
						}
					}
				}	
			}
		}
	}
}