C# Customization

I am trying to do a customization that checks for a radio button to be checked, if it is and the gl account first four digits fall into a range of 1300 - 1399 i want to display an error. I am currently stuck on trying to take the value that i am getting from the textbox and parse it to an int but only grab the first 4. Can someone provide some help or a path to do this easier?

My current code…

                GLAccountNum = (EpiGLAccountEditor)csm.GetNativeControlReference("1f3edba8-bf41-4a96-8f08-5a72281ec54f");
		RadioButtonValue = (EpiRadioButton)csm.GetNativeControlReference("7a2ae529-a68e-4bca-8517-cfd5ecb8f527");
		MessageBox.Show (GLAccountNum.Text);

		if (GLAccountNum.Text != null);
		{
			//GLAccountNumber = Convert.ToInt32(GLAccountNum.Text);
			Int32.TryParse(GLAccountNum.Text, out GLAccountNumber);
			MessageBox.Show (Convert.ToString(GLAccountNumber));
		}

		if (RadioButtonValue.Checked = true & (GLAccountNumber >= 1300 & GLAccountNumber < 1400));
		{
			MessageBox.Show ("Please update your number fool");
		}

int GLAccountNumber = Convert.ToInt32(GLAccountNum.Text.Substring(0,4));

1 Like

Below is the error i am receiving now. It does compile successfully.

Application Error

Exception caught in: mscorlib

Error Detail

Message: Index and length must refer to a location within the string.
Parameter name: length
Program: CommonLanguageRuntimeLibrary
Method: Substring

Client Stack Trace

at System.String.Substring(Int32 startIndex, Int32 length)
at Script.edvPODetail_EpiViewNotification(EpiDataView view, EpiNotifyArgs args)
at Ice.Lib.Framework.EpiViewNotification.Invoke(EpiDataView view, EpiNotifyArgs args)
at Ice.Lib.Framework.EpiDataView.OnEpiViewNotification(EpiNotifyArgs e)
at Ice.Lib.Framework.EpiDataView.Notify(EpiNotifyArgs args)
at Ice.Lib.Framework.EpiDataView.SetChildFilterAndNotifyChildViewWhenNoCurrentRow(EpiDataView childView, EpiNotifyArgs args)
at Ice.Lib.Framework.EpiDataView.SetChildFiltersAndNotifyChildViews(EpiNotifyArgs args, Boolean forceIt)
at Ice.Lib.Framework.EpiDataView.Notify(EpiNotifyArgs args)
at Ice.Lib.Framework.EpiTransaction.NotifyAll()
at Ice.Lib.Framework.EpiBaseForm.setupUIElements()

Try assigning the substring to a separate string variable first, and then running the convert separately.

I’ve often found nested methods that work elsewhere will error out in Epicor. It’s usually in an if statement, but I’ve seen it in string manipulation too.

1 Like

Try this:

		GLAccountNum = (EpiGLAccountEditor)csm.GetNativeControlReference("1f3edba8-bf41-4a96-8f08-5a72281ec54f");
		RadioButtonValue = (EpiRadioButton)csm.GetNativeControlReference("7a2ae529-a68e-4bca-8517-cfd5ecb8f527");
		MessageBox.Show (GLAccountNum.Text);

		if (!string.IsNullOrEmpty(GLAccountNum.Text)  && GLAccountNum.Text.Length>3)
		{
			GLAccountNumber = Convert.ToInt32(GLAccountNum.Text.Substring(0,4));
			MessageBox.Show (GLAccountNumber.ToString());
		}
		else
		{
			MessageBox.Show("GLAccountNum Error " + GLAccountNum);
		}

		if (RadioButtonValue.Checked = true & (GLAccountNumber >= 1300 & GLAccountNumber < 1400))
		{
			MessageBox.Show ("Please update your number fool");
		}
1 Like

I tried this and it still doesnt like the parsing.

I took my code out and put yours in and it did not like the else statement so i removed that and added int GLAccountNumber; and this also gave me the same error about parsing it out.

Sorry, I had a bad semicolon on the if statement. I fixed it in the code above.

EDIT: I now see that’s the issue with yours:

if (GLAccountNum.Text != null);

Both of your if statements have semicolons, that means the code after them always gets executed.

3 Likes

Yup! I dont know how i missed that LOL

It seems like it is working now :slight_smile: