# Customization Code Help - Specified Cast is not valid

**URL:** <https://www.epiusers.help/t/customization-code-help-specified-cast-is-not-valid/76761>\
**Category:** Epicor ERP 10\
**Tags:** customization\
**Created:** [March 18, 2021, 8:00pm UTC](https://www.epiusers.help/t/customization-code-help-specified-cast-is-not-valid/76761 "2021-03-18T20:00:15Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![tmcmullen](https://www.epiusers.help/letter_avatar_proxy/v4/letter/t/74df32/32.png) [@tmcmullen](https://www.epiusers.help/u/tmcmullen)\
**Post date:** [March 18, 2021, 8:00pm UTC](https://www.epiusers.help/t/customization-code-help-specified-cast-is-not-valid/76761/1 "2021-03-18T20:00:15Z")

</div>

I have a customization for a BAQ Report Form this is causing me issues. I am enabling an disabling the Generate button based on if there is a value (a Pack Slip Number) in the field on the form. If there is a value in the field and I delete it and press tab, I am getting the following error:

Application Error

Exception caught in: BAQReportSOPartSNTag.EP.COMSON.Customization.DisAllowNullPS.CustomCode.28

# Error Detail

Message: Specified cast is not valid.  
Program: BAQReportSOPartSNTag.EP.COMSON.Customization.DisAllowNullPS.CustomCode.28.dll  
Method: BAQReportParam\_AfterFieldChange

# Client Stack Trace

at Script.BAQReportParam\_AfterFieldChange(Object sender, DataColumnChangeEventArgs args)  
at System.Data.DataColumnChangeEventHandler.Invoke(Object sender, DataColumnChangeEventArgs e)  
at System.Data.DataTable.OnColumnChanged(DataColumnChangeEventArgs e)  
at Ice.Rpt.BAQReportDataSet.BAQReportParamDataTable.OnColumnChanged(DataColumnChangeEventArgs e)  
at System.Data.DataRow.set\_Item(DataColumn column, Object value)  
at System.Data.DataRowView.SetColumnValue(DataColumn column, Object value)  
at System.Data.DataRowView.set\_Item(String property, Object value)  
at Ice.Lib.Framework.EpiNumericEditor.TextValidate(Object sender, CancelEventArgs ea)

My code is below. I have tried everything I can think of and cannot get it solved. The Customization compiler does not give me an error or warning, it compiles successfully. I am doing the same thing on another BAQ Report Form with Job Number and I am not having any issues. What am I missing?

```cs
private void BAQReportParam_AfterFieldChange(object sender, DataColumnChangeEventArgs args)
	{
		// **Argument Properties and Uses**
		// args.Row["FieldName"]
		// args.Column, args.ProposedValue, args.Row
		// Add Event Handler Code
		switch (args.Column.ColumnName)
		{
			case "Field1":
			EpiDataView BAQReport = oTrans.Factory("ReportParam");
			
			int PackNum = (int)BAQReport.dataView[BAQReport.Row]["Field1"];

			if (PackNum == 0)
				baseToolbarsManager.Tools["GenerateTool"].SharedProps.Enabled=false;
				
			else
				baseToolbarsManager.Tools["GenerateTool"].SharedProps.Enabled=true;
				break;
		}
	}

```

---

<div class="post-metadata">

**Author:** ![josecgomez](https://www.epiusers.help/user_avatar/www.epiusers.help/josecgomez/32/55731_2.png) [@josecgomez](https://www.epiusers.help/u/josecgomez)\
**Post date:** [March 18, 2021, 8:05pm UTC](https://www.epiusers.help/t/customization-code-help-specified-cast-is-not-valid/76761/2 "2021-03-18T20:05:04Z")

</div>

Field1 is not likely an integer. Its probably a string?

---

<div class="post-metadata">

**Author:** ![ckrusen](https://www.epiusers.help/user_avatar/www.epiusers.help/ckrusen/32/50584_2.png) [@ckrusen](https://www.epiusers.help/u/ckrusen)\
**Post date:** [March 18, 2021, 8:21pm UTC](https://www.epiusers.help/t/customization-code-help-specified-cast-is-not-valid/76761/3 "2021-03-18T20:21:28Z")

</div>

If you delete the prior packnum from that filed it is now “null”, until the new record is fetched, at which time it will be an empty record whose packnum value defaults to 0.

Add an EndEdit (??) event on that control, and if it is blank, then set it to zero.

---

<div class="post-metadata">

**Author:** ![tmcmullen](https://www.epiusers.help/letter_avatar_proxy/v4/letter/t/74df32/32.png) [@tmcmullen](https://www.epiusers.help/u/tmcmullen)\
**Post date:** [March 18, 2021, 8:20pm UTC](https://www.epiusers.help/t/customization-code-help-specified-cast-is-not-valid/76761/4 "2021-03-18T20:20:21Z")

</div>

The field properties in the customization window state that the NumericType is an Integer. When I created this, I copied and pasted the code from the working Customization with Job Numbers and I received no errors from the compiler but I received the application error “Unable to cast object of type ‘System.Int32’ to type ‘System.String’.”. So I removed all the string casts from that code and replaced them with int. Another block of code was ok with that, but this block is not.

---

<div class="post-metadata">

**Author:** ![adaniell](https://www.epiusers.help/letter_avatar_proxy/v4/letter/a/278dde/32.png) [@adaniell](https://www.epiusers.help/u/adaniell)\
**Post date:** [March 18, 2021, 9:41pm UTC](https://www.epiusers.help/t/customization-code-help-specified-cast-is-not-valid/76761/6 "2021-03-18T21:41:01Z")

</div>

As a test, output the following

```auto
EpiMessageBox.Show(BAQReport.dataView[BAQReport.Row]["Field1"].GetType());
```

---

<div class="post-metadata">

**Author:** ![markamiller](https://www.epiusers.help/letter_avatar_proxy/v4/letter/m/9f8e36/32.png) [@markamiller](https://www.epiusers.help/u/markamiller)\
**Post date:** [February 10, 2022, 6:19pm UTC](https://www.epiusers.help/t/customization-code-help-specified-cast-is-not-valid/76761/7 "2022-02-10T18:19:44Z")

</div>

Thanks Adam. That helped me.
