Custom Validations

The workflow for a form sequence provides the ability to perform custom validations on the form input. Custom validations using the CreateValidationItem workflow activity can check for valid data input above and beyond the built-in validations for form fields within Forms Builder.

Single Validation

The workflow for a Request for Information (RFI) sequence includes a LookupReferenceItem activity that checks for a Reference Item Type of "Lead Source" with a Reference Item value of "Auto Shows". The out argument of the activity is a variable named "InvalidLead".

LookupReferenceItem - Lead Source

The "InvalidLead" variable is used in an If activity with a condition of "myLeadSource.Equals(invalidLead.Id)". If this condition is true (i.e., the lead is associated with a Reference Item value of "Auto Shows"), a custom validation message is displayed. This message is triggered by a CreateValidationItem activity, where the Messages variable is set to "formInstance.ValidationMessages".

Create Validation Item

The validation item can be designed to use a message type of Error, Information, or Warning. On the rendered form, the message types are displayed as follows:

Validation Message Types
Message Type Message Display in Renderer Next Transition allowed?
Error Red toaster popup No, user must correct the form input
Warning Orange toaster popup Yes
Information Blue toaster popup Yes

For form input that meets the validation criteria (no errors) specify "Not formInstance.ValidationMessage.HasErrors" in the Next Condition field of the form transition. This allows users to continue to the subsequent form.

Custom Validation

Placement of the Custom Validation

Place the custom validation sequence in the Trigger of the WaitForBookmark activity (labeled "Next") from the form on which you want to do the validation (Source: "RFI Basic" form in our example). The custom validation message will be displayed before the transition to the subsequent form (Destination: "Admission" form in our example).

Wait for book in State Machine

Note: The WaitForBookmark activity clears any previous validation items. Therefore, the custom validation should be done after the transition from the form that is being validated.

Multiple Validations

You can also use a workflow to create multiple validations for a particular form in a sequence.

If any Forms Builder or Anthology Student activity is placed between two CreateValidationItem activities, a local variable must be created for the ValidationMessages in-argument of that activity instead of the usual formInstance.ValidationMessages argument. This is necessary because the activity will overwrite any already existing ValidationMessages in formInstance.ValidationMessages if that is supplied as an argument.

In our example, a GetAttachments activity is placed between two validations with CreateValidationItem activities.

GetAttachments validation

A local variable of type ValidationMessageCollection is created and supplied to the GetAttachments activity.

Validation Message Collection

If the activity returns errors, the InvokeMethod activity adds the validation message to formInstance.ValidationMessages so it can be displayed in Renderer.

Supply a parameter for the Add method by clicking ellipsis button on the Parameters attribute in the Properties window. Specify validationmessage(0) in the Value field for the Parameters attribute.

InvokeMethod

The following images show the workflow section that contains the validation steps. It is placed in the Next transition after the form that contains the fields to be validated.

Validation N/A

Validation continued

Multiple Validations Items When Processing a Grid

You can use custom validations to validate multiple items when processing a grid. The custom validations can loop through an array of items and display all validation errors when the user attempts to save the data.

This example is based on a form in which the user enters an array of reference addresses. The workflow checks for a validation message on each item by setting the variable "singleValidation". The validation messages on the array items are then concatenated to the main formInstanceValidationMessages using the CreateValidationItem activity.

The custom validation sequence is placed in the Trigger section of the WaitForBookmark activity (labeled "Next") from the form on which you want to do the validation (Source: "PersonalDataSheet" in our example). The condition in the Next transition is set to "Not formInstance.ValidationMessages.HasErrors ". The custom validation message is displayed before the transition to the subsequent form (Destination: "Default-Frame" in our example).

Custom Validation - Grid

The following activities are used in the custom validation sequence:

  1. ForEach<>
  2. SaveEntity<>
  3. If
  4. CreateValidationItem
  5. InvokeMethod

Invoke method

  1. ForEach<>

    The ForEach<StudentRelationshipAddressEntity> activity loops through the reference addresses obtained through the "myAddresses" InArgument.

    ForEach

    The "myAddresses" argument is defined in the workflow as:

    myAddresses

    The myAddresses argument is set in the Model property on Text Box controls on the PersonalDataSheet form as:

    • vm.models.myAddresses[0].FirstName
    • vm.models.myAddresses[0].LastName
    • vm.models.myAddresses[0].RelationToStudent
    • vm.models.myAddresses[0].StreetAddress
    • vm.models.myAddresses[0].City
    • vm.models.myAddresses[1].FirstName, etc.
  2. SaveEntity<>

    The SaveEntity<StudentRelationshipAddressEntity> activity uses the "singleValidation" variable as InArgument for the ValidationMessages collection.

    SaveEntity

    The "singleValidation" variable is defined in the workflow as:

    singleValidation

  3. If

    The If activity uses the Condition "singleValidation.HasErrors". If errors are found, the sequence containing the CreateValidationItem activity is executed.

    singleValidation.HasErrors

  4. CreateValidationItem

    The CreateValidationItem activity is set to a Message Type of "Error" for the InArgument of "formInstanceValidationMessages".

    The Message string displayed by the activity is defined as:

    "Check address for Reference " & reference.FirstName & " " & reference.LastName & " Error: " & singleValidation(0).Message

    Note that the "singleValidation" variable is used to hold the validation value for each item in the array.

    singleValidation.HasErrors message

  5. InvokeMethod

    The InvokeMethod activity is used to clear a singular collection for the next iteration of the loop. Otherwise the failure of a previous item in the array would remain and trigger the next item to show a failure as well.

    Invoke method