Skip to main content
Version: 8.1

Implement the validation of a Date/Time type field on a record page

Level: intermediate
Example

Validate the Created on field of the Date/Time type on the opportunity page. The date value of the Created on field must be earlier than the Closed on date.

Create a replacing view model schema of the opportunity page

  1. Go to the Configuration section and select a custom package to add the schema.

  2. Click AddReplacing view model on the section list toolbar.

  3. Fill out the schema properties.

    • Set Code to "OpportunityPageV2."
    • Set Title to "Opportunity edit page."
    • Select "OpportunityPageV2" in the Parent object property.
  4. Add a localizable string.

    1. Click the button in the context menu of the Localizable strings node.

    2. Fill out the localizable string properties.

      • Set Code to "CreatedOnLessDueDateMessage."
      • Set Value to "Created on must be less than Closed on."
    3. Click Add to add a localizable string.

  5. Implement validation of the Date/Time type field.

    To do this, implement the following methods in the methods property:

    • dueDateValidator(). The validator method that checks whether the condition is true.
    • setValidationConfig(). The overloaded base method that binds the validator method to the DueDate and CreatedOn columns.

    View the source code of the replacing view model schema of the opportunity page below.

    OpportunityPageV2
    define("OpportunityPageV2", [], function() {
    return {
    /* The name of the record page object's schema. */
    entitySchemaName: "Opportunity",
    /* The methods of the section page's view model. */
    methods: {
    /* The method that validates the [DueDate] and [CreatedOn] column values. */
    dueDateValidator: function() {
    /* The variable that stores the validation error message. */
    var invalidMessage = "";
    /* Check the [DueDate] and [CreatedOn] column values. */
    if (this.get("DueDate") < this.get("CreatedOn")) {
    /* If the [DueDate] column value is earlier than the [CreatedOn] column value, put the localizable string that contains the validation error message in the invalidMessage variable. */
    invalidMessage = this.get("Resources.Strings.CreatedOnLessDueDateMessage");
    }
    /* The object whose property contains the validation error message. If the validation is successful, the object returns an empty string. */
    return {
    /* The validation error message. */
    invalidMessage: invalidMessage
    };
    },
    /* Overload the base method that initalizes the custom validators. */
    setValidationConfig: function() {
    /* Call the initialization of the parent view model's validators. */
    this.callParent(arguments);
    /* Add the dueDateValidator() validator method for the [DueDate] column. */
    this.addColumnValidator("DueDate", this.dueDateValidator);
    /* Add the dueDateValidator() validator method for the [CreatedOn] column. */
    this.addColumnValidator("CreatedOn", this.dueDateValidator);
    }
    }
    };
    });
  6. Click Save on the Designer's toolbar.

Outcome of the example

To view the outcome of the example:

  1. Refresh the Opportunities section page.
  2. Enter the date earlier than the Created on field value in the Closed on field.

As a result, Creatio will display the corresponding warning on the opportunity page.

If you try to save an opportunity where the date value of the Closed on field is earlier than the Created on date, a message box will open.


Resources

Package with example implementation