Writing a Process Flow to Impose Validation Logic Example

In some cases, an organization may want to use Aptify's Process Pipeline functionality to impose validation logic to the system rather than having to write an organization-specific entity object or a validation script for one or more Entity Fields.

In order to support these types of process flows, Aptify provides the BeforeValidate and AfterValidate event definitions (see About the Delivered Event Definitions). These are Entity-scoped events tied to the Aptify Generic Entity. When a process flow is tied to one of these events, the Process Flow Engine determines if a record passes or fails validation based on the process flow's result: Success or Failed. Note that this differs from other types of events where a Failed result typically indicates that the process flow failed to execute.

Keep in mind the following important points when working with validation process flows that fire using the BeforeValidate or AfterValidate event:

  • The validation events support a ValidationMessage property so a process flow designer can specify the text of the error message that appears when validation fails (the system uses the ValidationMessage as the LastError and LastUserError in the Aptify Generic Entity). A validation process flow can support the following outcomes:
    • If the process flow's result is a Success result code and the ValidationMessage property is empty, the validation was successful.
    • If the process flow's result is a Failed result code and the ValidationMessage property has a value specified, a message box appears to the end user displaying the ValidationMessage text.
    • If the process flow's result is a Failed result code and the ValidationMessage property is empty, the following generic message is displayed when validation fails: Validation has failed but no information about the failure has been provided.
    • Note that the fourth option where a process flow's result is a Success result code and the ValidationMessage property is not empty will result in a validation failure and the validation message is displayed. However, this is not an expected outcome since a validation failure is expected to correspond to a process flow failure.
  • The validation in the Aptify Generic Entity will not proceed if the BeforeValidate Event fails (Result Code of false or Failed). Therefore, the AfterValidate Event will not be fired if the BeforeValidate Event fails.

  • Unlike other Aptify delivered events that only fire for top-level entities, the BeforeValidate and AfterValidate events fire for Sub-Type entities. In these cases, the system validates sub-type records (and fires the event) twice: once when the record is closed (for example, when a user clicks the OK button) and a second time when the top-level entity record is saved.

This topic provides an example of how to write a simple validation process flow and tie it to the AfterValidate event. Note that this tutorial references records found in Aptify's sample dataset.

Business Case and Designing the Validation Process Flow

In the first step of the Validation Process Flow tutorial, the Human Resources director at Sampco Holdings, Inc. requires that all Sampco employees be linked either to the parent organization or one of its subsidiaries but not to any inventory warehouses, which also appear as Organizations records. The director has requested validation logic to prevent users from linking any employee to an inventory warehouse.

In the data, Organization records 1 to 6 correspond to the parent company and its subsidiary while records 7 to 10 corresponds to warehouses.

Sample Organizations

Rather than write a field validation script for Employees. OrganizationID, the Sampco implementation team has decided to write a validation process flow to check that new employees are not linked to organizations record that corresponds to a warehouse location.

Outlining the Validation Process Flow

The first step in any process flow configuration is to outline the process.

How Many Steps?

To add this validation logic to Aptify as a process flow, you need to create a two-step process flow. When Employees records are saved within Aptify, the process flow must validate that the employee is not linked to a warehouse organization. So, the first step in the process flow will be to retrieve and test the value returned for the employee's organization.

The second step in the process is to display an appropriate Validation Message if the employee is linked to an inappropriate organization. (If linked to an appropriate organization, the process flow would end after step 1).

What Data Will the Process Flow Use?

The process flow will need to retrieve the Organization ID from the current GE object for the Employees record that is being saved.

Linking the Validation Process Flow to an Entity

Event Handlers are used to link process flows to entities or applications. In this case, since the process flow is executing validation logic for the Employees entity, we need to create an Event Handler for the Employees entity using either the BeforeValidate or AfterValidate event definition. For BeforeValidate, the system will run the process flow before executing the standard Generic Entity (GE) validation. For AfterValidate, the system will run the process flow after executing the standard GE validation. We can link the event handler to either event but for the sake of this example, we will link it to the AfterValidate event (so it occurs after the standard validation).

Perform the following steps to set up the event handler:

  1. Select the Process Pipeline Administration application to load its dashboard.
  2. In the Event Handler Management area, select Entities as the Event Scope.
  3. Enter Employees in the Entity field. Upon tabbing out of the field, the grid below displays with a list of all other Event Handlers attached to the Employees entity, if any.
  4. Click Add Event. The Event Handler form now displays.
  5. In the Event field, enter AfterValidate.
  6. In the Process Flow field, enter the XY Validate Organization process flow.
    • Once the Process Flow field is filled, the Input Map tab populates with the input property defined on the process flow selected.
  7. For the GEObject input property, select GE Object as the Source Type. GEObject will then automatically populate in the Source field.

    Configuring the Event Handler
  8. Click OK to save the record.
  9. Close the Aptify application and restart before continuing.

Testing the Validation Process Flow Event

In the final step in the Validation Process Flow tutorial, the process flow has been created and linked to the Employees entity. All that remains now is to test the functionality. To do this:

  1. Open a new record from the Employee service.
  2. Enter a first and last name.
  3. Enter a warehouse in the Organization field (that is, enter an Organizations record with an ID greater than 6).
  4. Save the record.
    • The validation message specified in the process flow's Rule step appears. This message is also logged to the Aptify Session Exceptions viewer.

      Sample Validation Logic Imposed
  5. Click OK to close the validation message.
  6. Change the new employee's affiliation to a non-warehouse organization (such as ID 5).
  7. Save the record.
    • The record saves successfully.
  8. Try to change an existing employee to associate with a warehouse Organization. You should get the same results as above for a new Employees record.

Cleaning Up

Unless you make the Event Handler inactive, you will continue to impose the validation logic on your test system.

  1. Open the Event Handler created in this example.
  2. Clear the Active option.
  3. Click OK to save the record, then exit the Event Handler Management form.

For best results, close Aptify and reopen the application before performing any more processing within the system.

Was this article helpful?
0 out of 0 found this helpful



Please sign in to leave a comment.