Skip to main content
Version: 8.1

Set the default value for a field on a record page

Level: intermediate
Example

Specify the default value for the Deadline field on the page that adds a project. The Deadline field value must be 10 days greater than the Start field value.

Create a replacing view model schema of the project 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 "ProjectPageV2."
    • Set Title to "Project edit page."
    • Select "ProjectPageV2" in the Parent object property.
  4. Set up the field population logic.

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

    • onEntityInitialized(). An overloaded base virtual method. Called after Creatio initializes the object schema. Call the setDeadline() handler method in the onEntityInitialized() method. The handler method ensures the Deadline field value is set when a record page opens.
    • setDeadline(). The handler method that calculates the Deadline field value.

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

    ProjectPageV2
    define("ProjectPageV2", [], function() {
    return {
    /* The name of the record page object's schema. */
    entitySchemaName: "Project",
    /* The methods of the record page's view model. */
    methods: {
    /* Overload the base Terrasoft.BasePageV2.onEntityInitialized method that is called after Creatio initializes the schema of the record page object. */
    onEntityInitialized: function() {
    /* Call the parent implementation of the method. */
    this.callParent(arguments);
    /* Call the handler method that calculates the [Deadline] column value. */
    this.setDeadline();
    },
    /* The handler method that calculates the [Deadline] column value. */
    setDeadline: function() {
    /* The [Deadline] column value. */
    var deadline = this.get("Deadline");
    /* Checks whether the mode of the new record is set. */
    var newmode = this.isNewMode();
    /* If the value is not set and the mode of the new record is set. */
    if (!deadline && newmode) {
    /* Retrieve the [StartDate] column value. */
    var newDate = new Date(this.get("StartDate"));
    newDate.setDate(newDate.getDate() + 10);
    /* Set the [Deadline] column value. */
    this.set("Deadline", newDate);
    }
    }
    }
    };
    });
  5. Click Save on the Designer's toolbar.

Outcome of the example

To view the outcome of the example, refresh the Projects section page.

As a result, Creatio will set the date value of the Deadline field that is 10 days later than the Start date on the page that adds a project.


Resources

Package with example implementation