Field validation on leave

I have the validation working the way I want it. On part number, and on bin locations (with the warehouse)

The next thing that I want to do is to be able to do have the form work like most of the other forms in E-10 work, where I type in value in to Key1 and it either looks up the number in the table, or if it doesn’t exist ask if you want to make a new one.

I’m looking at the trace and the method that should be called is GetRows() right? So again, I can’t find that in the object explorer, so I’m having trouble figuring out how to use it. Is this an adapter method that I need to use? And if I do, do I have to link all of the values to all of my text boxes after looking it up?

Well, there are again many ways to accomplish this, but if I were you, I might consider which data I need it to display and such first. In a regular E-10 form, there are EpiDataViews. The form controls (text boxes, etc.) are bound to the dataview columns and will change based on the value in the dataview.

If you have a few fields you want to bind to form controls after returning a dataset from a record lookup (i.e. GetByID), you could just set the values of the controls equal to the returned record set.

You could get really complicated with this if you wanted, but it all depends on the usage…

You can just do a GetByID here as well and just handle the case where there is no record found.

If no record is found, you’ll have to create by tracing the steps used when manually creating a record of the desired type.

what about when there is a record? If I do a new record and then type in an existing number, it doesn’t stop me until I try to save it. I want it to load the existing one at that point.

Yes so i think generally GetByID() returns a true/false depending on whether the record exists or not. So if it returns true, your record should be in the adapter data, if not, use the adapter to create

So I can do the GetByID, but then can I load the row without having to get each specific value and putting into each text box?

This is what I have, it works in that it tells me if the number is new or not, but how can I abandon the Get new record process and just load the existing one?

		switch(args.Column.ColumnName)
		{
			case "Key1":
			UD10Adapter adapterUD10 = new UD10Adapter(oTrans);
			adapterUD10.BOConnect();
			try
				{
				adapterUD10.GetByID(Key1Box.Value.ToString(),"","","","");
				MessageBox.Show("This is an existing number");
				}
			catch
				{
				//adapterUD10.GetaNewUD10();
				MessageBox.Show("this is a new number");
				}
			adapterUD10.Dispose();
			break;
		}

Maybe I misunderstood the intention. So you are saying you have an existing EpiDataView and you want to load the record into that?

Look at the UD10 adapter that already exists on the form and use that, it will already be wired up to the EDV on the form. So if you do a GetByID on that adapter, it should populate the screen

How do I do that? That’s what I’m trying to learn. How do I find what’s already there to use?

Well I’d probably do it via reflection to grab the private adapter. I think there is a call to get form adapters like:
oTrans.HTAdapters[“adapter name”];

But i never use that. In this particular case I think you should just be able to call:
oTrans.GetByID(k1,k2,k3,k4,k5);

Do you know how to abandon a get new in process on that call? It works, but if I have a new record in process, this row is added and the old one hangs out there buggering things up.

Sure, but you can avoid that by putting logic in to only do GetNew if it doesnt exist.

But for the sake of science, assuming its the latest row i think this should work:

var UD10 = oTrans.Factory("UD010");
UD10.dataView[UD10.dataView.Count -1].Delete();

We’re actually only deleting the row, because until you commit with an Update, it really doesnt exist

If someone hits the new button, then types this in, not knowing that it already existed, it’s pretty hard to get them to not hit the new button.

If they are on an existing record and want to enter a new one, the fields for key1 is grayed out, so they can’t enter a number in that field until they hit new.

This code works with typing existing, but if won’t let me do a new record now.

well… not sure why index 2 is invalid, I clearly see 3 items 0,1,2

Is it possible the code is being called more than once?

2 quick options.
Try oTrans.Undo() instead.
warp the code in try/catch to see if behaves

Redacted… i was thinking UDXXA

Ok i think i understand what you are doing now. Perhaps the easiest way is to replace the Key textbox (hide it) with a custom. Then do all your logic on the custom, and pass the data to the Key field as needed

This will let you type in without creating new. It looks up, if found it loads, if not, create new.

ok. I’ll try that.

To be able to do that, I pretty much have to hijack basically everything in the UD entry screen and re-write it then? Correct? I can’t use any of the native Key fields, and I have to wire up custom controls to write to these fields. Does that seem like it’s the right way to go about this?

Nah, you still access all the data with EpiDataView and controls are still bound.

The only difference is, your logic is on your control.

if(!oTrans.GetByID()) //which should load the record if it is found
{
  //not found 
  oTrans.GetNew(YourKeyValue, ...)
  //now all the controls on form work as before

}

So where to I put that? On a field leave event for this new pseudo key1 field?

What happens if the user clicks the new button then? What do I bind this new text box to? Or is it just unbound?

LoL I was gonna try to help but holy crap batman TL;DR LMAO… anyone have cliff notes?

1 Like

I just want the key1 field to load an existing record if there is one. (like just about every native epicor form)

I wouldnt bind it to anything, I’d just handle the logic in the OnLeave.

As far as the New Button goes, personally in this case, I’d disable/hide it. But… you can keep as long as you handle the case.

Perhaps you can check for the blank row in the dataView BEFORE GetNew
if(UD10.dataView[UD10.Row]["RowMod].ToString() == “A”)
{
//the current record is a new one…
}