Create Custom Validations

This page describes how to create custom validations of entered data in a window that is developed with the Application Forms framework.

Custom validation is done on data items. A data item is a data field, column, combo box, checkbox etc, that is connected to an SQL column in a data source. The framework sends the message PM_DataItemValidate to a data item when it needs to be validated. This typically happens when a data item loses focus. The framework performs some validation automatically and applications only need to catch the PM_DataItemValidate to perform additional validation. The application shall return VALIDATE_Ok when validation is successful and VALIDATE_Cancel if the validation is not.

In order to add the message handling, a window object must subscribe to the window actions event. Here is a code example on how to catch the message PM_DataItemValidate and perform some custom validation:

private void dfsCustomerNoPay_WindowActions(object sender, WindowActionsEventArgs e)
{
	switch (e.ActionType)
	{
		case Ifs.Fnd.ApplicationForms.Const.PM_DataItemValidate:
			this.dfsCustomerNoPay_OnPM_DataItemValidate(sender, e);
			break;
	}
}

Figure 1: Window actions event handler handling PM_DataItemValidate.

private void dfsCustomerNoPay_OnPM_DataItemValidate(object sender, WindowActionsEventArgs e)
{
	e.Handled = true;
	this.CustomerNoPayControl(this.dfsCustomerNoPay.Text);
	e.Return = Sys.VALIDATE_Ok;
	return;
}

Figure 2: Custom validation method.

Apart from custom validation the framework performs validation to check that mandatory fields have a value. This is typically done during the save process and when you have a new row in a table window and create yet another new row.

The framework also calls a server method automatically if a method is provided in the property Validate Method. The specified server method is called by the framework if PM_DataItemValidate message returns VALIDATE_Ok. The method to call should be a PL/SQL method that returns TRUE or FALSE. If the method uses parameters, the parameters should be a view column that is databound in the window.

Figure 3: The Validate Method property in the Visual Studio property sheet.