Field validation on leave

Is it possible to use a BPM for field validation on leave for a UD screen? I want to check for a valid part number and bin location. I know how to do it via BPM on update, but I would like to check on field leave just for ease of use. Does that have to be coded in the customization?

Well it depends on the form, but most controls would not have a server side method triggered on leave. The exception would be like QuoteDtl.ChangePartNumMaster, but I think what you’re asking is if there is a universal server side event on leave, and there is not (to my knowledge).

1 Like

That’s a good point. I forgot about the server side vs client side split.

I’ll probably just live with the update method. I can tell them what’s wrong, and it’s for an occasional use screen anyways.

Maybe I could just call update on leave if the field isn’t null or empty? If I’m updating a UD table that update should be so fast that it shouldn’t have any performance hit. That might work nicely.

Is the user always going to be entering validated input via the customization or can data flow into this table another way? You could always use a combination of client side code and BPM code if you wanted, I think it just depends on your requirement. The nice thing about client side is that it could be really quick validation accompanied by a clearing and re-focusing on that field.

It will always be through the customization. Mostly, I suck at C#, so client side validation is simply harder for me. BPM’s have nice condition blocks, message boxes, fill by query etc, that I can use for that so it’s easier for to actually accomplish.

Sounds like an opportunity to get better at C# then! :slight_smile:

2 Likes

Sounds like I found myself a teacher? Ehh? :wink:

I’ve been trying to google some things on database validation. I haven’t found an example that I can understand yet. If you have a link or anything to a good post or site that would be awesome. It is something I need to learn.

I’d be happy to help if I can!
First off, what are you trying to test for before the data is submitted to the database? That would be a good place to start…

I want to input a part number into a UD field. I want that field to only be allowed to have valid part numbers. Same thing for Bin numbers. Pretty simple actually.

This is actually pretty close to what I am looking for. I should spend some time understanding what this is doing so I can know what I need to modify.

That’s server side…

1 Like

Ok, that’s actually pretty easy then. So the concept would be that, upon the field leave event firing, your code needs to go out and check for the record existing in either the part table or the bin table. You can call a getByID on those business objects and if it returns a record, you’ll pass the validaion. If it fails, you’ll fail your validation and then do something else.

That makes sense. I was thinking there was some special validation code. GetByID should work fine. I’ll see what I can figure out tomorrow.

1 Like

Alright, getting back to this now. I have the UDscreen set up to enter the data that I want in there. I’m starting with the part number validation first. I think that I will need adatpers.part in order to do a getByID, right?

I’m trying to get this stuff set up, but I need help on even the basics.

First, need to set up the text box in the code right?

so

EpiTextBox PartNumBox;

and

PartNumBox = (EpiTextBox)csm.GetNativeControlReference("368fd000-b055-4183-9d70-25d986650bd9");

right?

Then I set up my leave event with the wizard.

	private void PartNumChar01_Leave(object sender, System.EventArgs args)
	{
		// ** Place Event Handling Code Here **
		
	}

Next I’m going to need to be able to bring in a dataset with the part adapter. This is where I don’t know what to do.

I’m guessing that I need to go into the custom assembly reference manager and add Erp.Adapters.Part right?
image

Then do I have to set up the module variables to hold the data set?
something like this?

private EpiDataView edvPart;

So I think I have a text box, that is bound to the variable PartNumBox, a Data View edvPart, and an event to trigger it to lookup/populate.

This where I get stuck. I need no how to code the GetByID in the event.

I’ve been trying to find an example, but most of the ones that I am coming across do a bunch of extra stuff that I don’t need, so I’m having a hard time figuring out what is required, and what I can leave off.

Anyone willing to help?

Assuming you added the adapter via the wizard…
To access an adapter, you need to reference the following:

using Erp.Adapters or Ice.Adapters, depending on the schema.

Next, inside your leave event, you need to instantiate the adapter.

PartAdapter adapterPart = new PartAdapter(oTrans);
adapterPart.BOConnect();
if(adapterPart.GetByID(yourPartNumString))
{
//do something if successful
}
adapterPart.Dispose();

1 Like

so Ice.Adapters; was already in there. But that would be for the UD tables right? I think I would also need Erp.Adapters for the part adapter since that is in the Erp section? I tried it without Erp, and it didn’t compile, with it did, so we’ll assume I need it. And we’ll assume my logic is correct as to why :wink:

I have your code in there. It compiles and I threw a message box in there to make sure it fires. It does BUT it fires no matter what, so it’s not really validating. Am I doing something wrong? or is there something else I need to add in there.

Share your code so I can see what it’s doing :slight_smile:

here it is.

// **************************************************
// Custom code for UD10Form
// Created: 8/30/2018 10:49:49 AM
// **************************************************
using System;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Windows.Forms;
using Ice.BO;
using Ice.UI;
using Ice.Lib;
using Ice.Adapters;
using Ice.Lib.Customization;
using Ice.Lib.ExtendedProps;
using Ice.Lib.Framework;
using Ice.Lib.Searches;
using Ice.UI.FormFunctions;
using Erp.Adapters;

public class Script
{
	// ** Wizard Insert Location - Do Not Remove 'Begin/End Wizard Added Module Level Variables' Comments! **
	// Begin Wizard Added Module Level Variables **

	// End Wizard Added Module Level Variables **

	// Add Custom Module Level Variables Here **

	public 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


		this.PartNumBox.Leave += new System.EventHandler(this.PartNumBox_Leave);
		// End Wizard Added Custom Method Calls
		PartNumBox = (EpiTextBox)csm.GetNativeControlReference("368fd000-b055-4183-9d70-25d986650bd9");
	}

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

		this.PartNumBox.Leave -= new System.EventHandler(this.PartNumBox_Leave);
		// End Wizard Added Object Disposal

		// Begin Custom Code Disposal

		// End Custom Code Disposal
	}



	private void PartNumBox_Leave(object sender, System.EventArgs args)
	{
		// ** Place Event Handling Code Here **
	PartAdapter adapterPart = new PartAdapter(oTrans);
	adapterPart.BOConnect();
	if(adapterPart.GetByID(PartNumBox))
		{
		MessageBox.Show("it worked");
		}
	adapterPart.Dispose();
	}
}

I warned you I suck at C#…

Ok. You want the value of the part num being entered into the PartNumBox control, right? Right now, you’re passing in the PartNumBox control itself, so I’m not even sure how that’s working.
What you need is to grab the value of the part number that you’re entering into this field.

Where is your proposed part number coming from? If you want, try hard coding both a valid part code and a nonvalid part code into that GetByID method and see how it behaves when you leave the PartNumBox field.

The proposed is coming from the textbox field tied to UD10.Character01.

Let me try the hard coded route.

When I hard code the number it works as expected. Goes through when correct, not when invalid.

So how do I get the value of the text box? I’ve only really dealt with grids so far.

	private void PartNumBox_Leave(object sender, System.EventArgs args)
	{
		// ** Place Event Handling Code Here **
	PartAdapter adapterPart = new PartAdapter(oTrans);
	adapterPart.BOConnect();
	var PartNum = PartNumBox.Value.ToString();
	if(adapterPart.GetByID(PartNum))
		{
		MessageBox.Show("it worked");
		}
	adapterPart.Dispose();
	}

I added var PartNum = PartNumBox.Value.ToString(); and it kind of works. It doesn’t want to seem to grab it every time though. Or it seems like it’s holding onto the old value. I think I need something to refresh it.