Field validation on leave

Ok good. Is the user entering in the part num into this field? If so, just take the value of the PartNumBox field.
Keep in mind there are many many ways to skin this cat.

Yes. The user is typing in the part number, and I want to validate that itā€™s a good part number before they move on.

If youā€™ve got a better way to skin this cat, Iā€™m all ears. Iā€™m just trying to apply what little I know. Please correct me if I so something dumb.

I think what youā€™re doing is fine for this purpose.

so what do I have to do to get it to grab the value in the box the first time? Do I have the right event?

Hmm. Grabbing the value from a control can sometimes be messy. If you want, you could try handling this off of the dataview instead. You could potentially hang this code off of a ā€œBeforeFieldChangeā€ event and would have access to the ā€œproposed valueā€, which you could test on. It would also allow a rollback

1 Like

ok, we can try that. If I use the wizard to add that, I get this code from the wizard. Now I donā€™t need the value from the text box because I am using UDCharacter01 right? How do I plug in the GetById to the switch case?

private void UD10_BeforeFieldChange(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 "Character01":
				break;
		}
	}

Well, you could plug it in very much like youā€™re doing on the Leave event.

private void UD10_BeforeFieldChange(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 ā€œCharacter01ā€:
PartAdapter adapterPart = new PartAdapter(oTrans);
adapterPart.BOConnect();
if(adapterPart.GetByID(args.ProposedValue))
{
MessageBox.Show(ā€œit workedā€);
}
adapterPart.Dispose();
break;
}
}

Thanks, It was the args.ProposedValue part that I didnā€™t know.

Unfortunately, itā€™s doing the works no matter what thing again.

	private void UD10_BeforeFieldChange(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 "Character01":
			PartAdapter adapterPart = new PartAdapter(oTrans);
			adapterPart.BOConnect();
			if(adapterPart.GetByID(args.ProposedValue))
			{
			MessageBox.Show("it worked");
			}
			adapterPart.Dispose();
			
			break;
		}		
	}

If i were you, Iā€™d play around with the data going into the column. Maybe first try doing some tests by showing the proposed value and how it interacts with the leave event? Rather than focus on the adapter for nowā€¦

This event seems to be working much better than the leave event. It only fires when there is a change, which is much better. I added the args.ProposedValue into the ā€œit workedā€ message box, and the value coming through is matching what is in the text box. So that seems to be working great.

Edit, it need .ToString(). Now it works as expected.

	private void UD10_BeforeFieldChange(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 "Character01":
			PartAdapter adapterPart = new PartAdapter(oTrans);
			adapterPart.BOConnect();
			if(adapterPart.GetByID(args.ProposedValue.ToString()))
			{
			MessageBox.Show("it worked " + args.ProposedValue);
			}
			adapterPart.Dispose();
			
			break;
		}		
	}
1 Like

So I switched this over to a try statement, because I want to be able to display a message that says something intelligible. It doesnā€™t revert, but for this case, Iā€™m not worried about that. I will have BPMā€™s in place to catch the actual save event. (or I can try to throw an exception in this code too)

So I need to learn how to get something from that lookup other than just a validation. For this use case, I want to pull the part description and load it into a call context field so that I can display it in a text box. I would put that into the successful try block. Do I need a call to create a dataset here? Or does the GetByID do that already? I didnā€™t see any data set values in the trace so Iā€™m assuming that it doesnā€™t. But I also donā€™t see that in the trace for part entry either. Iā€™m trying to find examples, but havenā€™t found one close enough for me to understand.

{
		// ** Argument Properties and Uses **
		// args.Row["FieldName"]
		// args.Column, args.ProposedValue, args.Row
		// Add Event Handler Code
		switch (args.Column.ColumnName)
		{
			case "Character01":
			PartAdapter adapterPart = new PartAdapter(oTrans);
			adapterPart.BOConnect();
			try//(adapterPart.GetByID(args.ProposedValue.ToString()))
			{
			adapterPart.GetByID(args.ProposedValue.ToString());
			MessageBox.Show("it worked " + args.ProposedValue);
			}
			catch
			{
			MessageBox.Show(args.ProposedValue +" is not a valid part number");
			}
			adapterPart.Dispose();
			
			break;
		}		
	}

GetByID will return the dataset which is part of the adapter data.
To access the data, you would reference it like so:

adapterPart.PartData.Part[0].YourColumnHere

1 Like

Just for reference, when using the UD screen, you have to add Erp.Contracts.BO.Part as a custom reference to make that line work.

image

First order of learning. How do I look up what I can use with an adapter? Is that somewhere in the object explorer? I am trying to understand how to use adapters in general so the next time I want to use an adapter, I can figure out what I can do without help. I donā€™t want to have other people write my code for me forever.

ok, so now I have that value, and I can put it into a message box. How so I get that value to show up on the text box?

Iā€™m trying a bunch of stuff, but am not sure where I should be going. I have the text box bound to a BPM call context field. Should I simply have an unbound field and set it it code using the part adapter?

I wish learning this stuff wasnā€™t like pulling teeth.

I figured it out

I set up the text box in the variables then I can use use this code (I found the example in the object explorer) and it now sets the value.

			{
			adapterPart.GetByID(args.ProposedValue.ToString());
			DescBox.Value = adapterPart.PartData.Part[0].PartDescription.ToString();
			}
1 Like

The object explorer is your friend here

1 Like

Yeah, Iā€™m trying to figure out how to use it. Starting to get better and knowing what Iā€™m looking at. I was able to throw the lookup into an epiview notification and it works much better.

So I have the field validation working for the part number.

Next I need to get the field validation working for the bin number as well, but I am missing something.

I can get a second case to pop off, but itā€™s calling it successful when it shouldnā€™t be.

Iā€™m trying to find in the object explorer how to use GetByID for the WhseBinAdapter but I can find it. Can someone show me (with screen shots preferably) where in the object explorer I can find how I can do a lookup with the WhseBinAdapter?

Hereā€™s what I am trying to do, but the try is coming back successful when it shouldnā€™t.

		switch(args.Column.ColumnName)
		{
			case "Character02":
			WhseBinAdapter adapterBin = new WhseBinAdapter(oTrans);
			adapterBin.BOConnect();
			try
			{
			adapterBin.GetByID(args.ProposedValue.ToString());
			MessageBox.Show("bin lookup good");
			}
			catch
			{
			MessageBox.Show(args.ProposedValue +" is not a valid Bin number");
			}
			adapterBin.Dispose();			
			break;
		}

I even try removing the ToString() part, and then it comes up bad no matter what.

Itā€™s always going to show you message in the try because itā€™s simply falling through the code. If you make the message box contintigent on the return value of the GetByID, it should work the way you want.

Remember, GetByID returns a boolean, so if you do

bool recSelected = adapterBin.GetByID(args.ProposedValue.ToString());
if(recSelected)//meaning we found a bin
{
MessageBox.Show(ā€œbin lookup goodā€);
}

So I I had to add the warehouse in the lookup, now itā€™s working, but only for the warehouse that Iā€™ve coded.

Is there really no way to look this stuff up?

		switch(args.Column.ColumnName)
		{
			case "Character02":
			WhseBinAdapter adapterBin = new WhseBinAdapter(oTrans);
			adapterBin.BOConnect();
			try
			{
			adapterBin.GetByID("GEN",args.ProposedValue.ToString());
			MessageBox.Show(args.ProposedValue +" this is a good check");
			}
			catch
			{
			MessageBox.Show(args.ProposedValue +" is not a valid Bin number");
			}
			adapterBin.Dispose();			
			break;
		}