Form customization -- script method doesn't fire


I have this piece of code going into the form customization script for part maintenance. It should validate a secondary part number field, and insert the part description into a secondary description field.

It’s all compiling okay, but it just doesn’t do anything. The text is pasted in below. Note the messageboxes don’t fire.

Also tried: private void txtServicePartUsePart_Leave(object sender, System.EventArgs args) – no difference. No validation, no part description.

I just can’t see it. Any observation?



private void txtServicePartUsePart_Validating(object sender, CancelEventArgs args)
// ** Place Event Handling Code Here **
EpiDataView edv = ((EpiDataView)(oTrans.EpiDataViews["Part"]));

bool recSelected = false;

string whereClause = "PartNum = '" + txtServicePartUsePart.Text + "'";

DataSet dsPart = Ice.UI.FormFunctions.SearchFunctions.listLookup(oTrans, "PartAdapter", out recSelected, false, whereClause);

if (recSelected)
edv.dataView[edv.Row]["ServicePartUsePart_c"] = dsPart.Tables[0].Rows[0]["PartNum"];

edv.dataView[edv.Row]["UserChar4"] = dsPart.Tables[0].Rows[0]["PartDescription"];

edv.Notify( new EpiNotifyArgs(oTrans, edv.Row, edv.Column) );

else if (txtServicePartUsePart.Text == "")
edv.dataView[edv.Row]["ServicePartUsePart_c"] = "";

edv.dataView[edv.Row]["UserChar4"] = ""; // ----------------- this is line 81 ----------------

MessageBox.Show("'" + txtServicePartUsePart.Text + "'" + " is not a valid part number.");

edv.dataView[edv.Row]["ServicePartUsePart_c"] = "";

edv.dataView[edv.Row]["UserChar4"] = "";



I am not familiar with that event - is it on a specific control like a textbox? And not even one message box appears?

So you say that even the Leave event doesn’t fire? I frequently use the Enter and Leave events of controls so that shouldn’t be an issue (unless it’s a version specific issue)

Do you see the event wired up in form load and destroy?

Are there any other things happening in your customization that allows you to verify the customization is actually being loaded?

Hi Chris,

I never made that validation method work. I switched to one of the form
wizards - BeforeFieldChange. It works okay, but if I, say, try to stuff the
part number I read in from the data set into the secondary part number
field, it trips the change event again and starts an infinite loop. So I
just don’t do that part. :slight_smile:

I would like to have that functionality for when the user keys in a part
number in a different upper/lower case than is on the part table. Ah, well.




You need to either paste the event handler lines in your script header or use the event wizard to put it there automatically for the validating event. It should trigger as soon as you tab out or click off the field.


public static 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

	Script.txtServicePartUsePart.Validating += new System.ComponentModel.CancelEventHandler(Script.txtServicePartUsePart_Validating);
	// End Wizard Added Custom Method Calls

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

	Script.txtServicePartUsePart.Validating -= new System.ComponentModel.CancelEventHandler(Script.txtServicePartUsePart_Validating);
	// End Wizard Added Object Disposal

	// Begin Custom Code Disposal
	// End Custom Code Disposal

If you decided to stay with the BeforeFieldChange - you can differentiate which field fired the event and handle accordingly. This would stop your loop.