Custom: Job Receipts to Inventory

I’m not sure why my custom isn’t working.

I added a field NumRcvQty that will show the previously received amount. Any help would be appreciated. My code is below:

extern alias Erp_Contracts_BO_Part;
extern alias Erp_Contracts_BO_Warehse;

using System;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Windows.Forms;
using Erp.Adapters;
using Erp.Contracts;
using Erp.UI;
using Erp.BO;
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 edvPartTran;
private EpiBaseAdapter oTrans_recAdapter;
// End Wizard Added Module Level Variables **

// Add Custom Module Level Variables Here **
private bool flagCount = false;

public void InitializeCustomCode()
{
// ** Wizard Insert Location - Do not delete ‘Begin/End Wizard Added Variable Initialization’ lines **
// Begin Wizard Added Variable Initialization

  this.edvPartTran = ((EpiDataView)(this.oTrans.EpiDataViews["PartTran"]));
  this.edvPartTran.EpiViewNotification += new EpiViewNotification(this.edvPartTran_EpiViewNotification);
  this.oTrans_recAdapter = ((EpiBaseAdapter)(this.csm.TransAdaptersHT["oTrans_recAdapter"]));
  this.oTrans_recAdapter.AfterAdapterMethod += new AfterAdapterMethod(this.oTrans_recAdapter_AfterAdapterMethod);
  // End Wizard Added Variable Initialization

  // Begin Wizard Added Custom Method Calls

  // End Wizard Added Custom Method Calls
  NumRcvQty.ReadOnly = true;

}

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

  this.edvPartTran.EpiViewNotification -= new EpiViewNotification(this.edvPartTran_EpiViewNotification);
  this.edvPartTran = null;
  this.oTrans_recAdapter.AfterAdapterMethod -= new AfterAdapterMethod(this.oTrans_recAdapter_AfterAdapterMethod);
  this.oTrans_recAdapter = null;
  // End Wizard Added Object Disposal

  // Begin Custom Code Disposal

  // End Custom Code Disposal

}

private void edvPartTran_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))
{
if (edvPartTran.dataView[edvPartTran.Row][“JobNum”].ToString() == “”)
NumRcvQty.Value = 0;
}
else
{
NumRcvQty.Value = 0;

  	}
  }

}

private void CallJobProdSearchAdapterInvokeSearchMethod()
{
try
{
// Declare and Initialize EpiDataView Variables
// Declare and create an instance of the Adapter.
JobProdSearchAdapter adapterJobProdSearch = new JobProdSearchAdapter(this.oTrans);
{
if (!edvPartTran.HasRow)
{
adapterJobProdSearch.BOConnect();

  	// Declare and Initialize Variables
  	Ice.Lib.Searches.SearchOptions opts;
  		opts = new SearchOptions( SearchMode.AutoSearch);
  		opts.DataSetMode = DataSetMode.RowsDataSet;
  		opts.SelectMode = SelectMode.SingleSelect;
  		opts.PreLoadSearchFilter = "JobNum = '" + edvPartTran.dataView[edvPartTran.Row]["JobNum"].ToString() + "'";
  		// Call Adapter method
  		System.Windows.Forms.DialogResult diaRes = adapterJobProdSearch.InvokeSearch(opts);
  		//MessageBox.Show("count " + adapterJobProdSearch.JobProdSearchData.JobProd.Rows.Count.ToString());
  		if (adapterJobProdSearch.JobProdSearchData.JobProd.Rows.Count > 0)
  		{
  		//MessageBox.Show("recvQty " + adapterJobProdSearch.JobProdSearchData.JobProd[0]["ReceivedQty"].ToString());
  			NumRcvQty.Value = adapterJobProdSearch.JobProdSearchData.JobProd[0]["ReceivedQty"];
  			
  			if (Convert.ToDecimal(adapterJobProdSearch.JobProdSearchData.JobProd[0]["ReceivedQty"].ToString()) == Convert.ToDecimal(adapterJobProdSearch.JobProdSearchData.JobProd[0]["ProdQty"].ToString()) && Convert.ToDecimal(adapterJobProdSearch.JobProdSearchData.JobProd[0]["ReceivedQty"].ToString()) > 0)
  				MessageBox.Show("The production quantity has already been received to stock. Are you sure you want to continue?");
  		}
  		else
  		{
  			NumRcvQty.Value = 0;
  		}
  		// Cleanup Adapter Reference
  		}
  		//adapterJobProdSearch.Dispose();
  	}
  } catch (System.Exception ex)
  {
  	ExceptionBox.Show(ex);
  }

}

private void oTrans_recAdapter_AfterAdapterMethod(object sender, AfterAdapterMethodArgs args)
{
// ** Argument Properties and Uses **
// ** args.MethodName **
// ** Add Event Handler Code **

  // ** Use MessageBox to find adapter method name
  // EpiMessageBox.Show(args.MethodName)
  switch (args.MethodName)
  {
  	case "GetNewJobAsmblMultiple":
  	case "GetList":
  	case "GetNewReceiptsFromMfgJobAsm":
  		flagCount = true;
  	break;
  	//case "GetAvailTranDocTypes":
  	case "EnableSerialNumbers":
  		if (flagCount)
  		{
  			CallJobProdSearchAdapterInvokeSearchMethod();
  			flagCount = false;
  		}
  		break;
  }

}
}

Looks like you want a messgebox to pop up and show any previously received - JobProd.ReceivedQty?

I wonder if you have tried the lookup in a BeforeFieldChange instead of the EpiDataView notification?
Just a guess, off the top of my head… based on a similar lookup I previously added to the End Activity form in MES.

Alternatively… in another, similar customization, I added have used FKV(s)
instead of custom code to lookup related values.
i.e. sometimes I add “reference only” display fields instead of a using a messagebox.
Ref screen shots of a quick example of customization I added to the Job Receipt to Inventory form.