Creatio development guide
PDF
This documentation is valid for Creatio version 7.11.0. We recommend using the newest version of Creatio documentation.

How to set a default value for a field

Glossary Item Box

Bpm'online has the possibility to set default values for control items of the edit page.

A default value may be set by two ways:

1. Set at the level of business object columns.

In most cases, when creating a new object, specific fields of the page must be filled in with certain values. In such cases, these values must be specified in the object designer as default values for the object columns corresponding to these fields.

2. Set in the source code of the edit page.

In some cases, a default value cannot be set using object column properties. For example, this may be a computed value that is calculated using values in other object columns, etc. In this case, the default value may be set using software only.

Both cases of setting a default value are described further below using specific examples.

Example of setting a default value for a field using object column properties.

Case description

 Create a new activity with the [Show in calendar] checkbox selected by default.

Case implementation algorithm

 1. Create an [Activity] replacement object in a custom package (or open an existing object)

For this purpose, select a custom package and run the [Add] > [Replacing Object] menu item on the [Schemas] tab (Fig. 1).

Fig. 1. – Creating a replacement object

To allow a module to replace a certain object, the base object name to be replaced must be specified in the [Parent Object] field.

This means that to create the [Activity] replacement object, it must be specified as the parent object.

When the selected parent object is confirmed, the remaining fields of properties are filled in automatically (Fig. 2).

Fig. 2. — Properties of the [Activity] replacement object

 2. Set a default value for the [Display in Calendar] column

For this purpose, select the [Show in calendar] column in the list of inherited object columns and edit its [Default Value] property as shown in Figure 3.

In general, the system proposes the following types of default values:

Constant String, number, value from lookup, logic value.
System setting The full list of settings is available in the configuration in the [System Settings] section and it may be supplemented by a custom system setting.
System variable

The bpm'online system variables are global variables storing data on the system settings. However, unlike system settings whose values may vary for various users, the values of system variables are fixed for all users. The full list of system variables is implemented at the core level and cannot be modified by a user:

  • New ID;
  • New successive ID;
  • Current user;
  • Current user contact;
  • Current user account;
  • Current date and time value;
  • Current date value;
  • Current time value.
No default value is specified

To implement the case, the constant value is selected as the default value.

Fig. 3. – Setting a default value for the [Show in calendar] column

3. Publish the object schema

When the schema is published and the system web-page is updated, the [Display in Calendar] checkbox will be selected automatically on the activity edit page when creating a new activity (Fig. 4).

Fig. 4. Demonstrating the default value setting

Example of setting a default value in the source code of the edit page

Case description

When creating a new project, the [Deadline] field value on the project edit page must be the [Start] value + 10 days by default.

Case implementation algorithm

1. Create a replacement project edit page in a custom package

A replacement client module must be created and [Project edit page] must be specified as the parent object in it (Fig. 5).

The procedure for creating the replacement page is described in the article Creating a custom client module schema.

Fig. 5. — Properties of the replacement edit page

2. Add the setDeadline handler method to the methods collection of the view model.

3. Add the redefining of the onEntityInitialized base method to the methods collection of the view model.

Below is the full code for the replacement schema of the project edit page. 

define("ProjectPageV2", [],
    function() {
        return {
            // Name of the edit page object schema.
            entitySchemaName: "Project",
            details: /**SCHEMA_DETAILS*/{}/**SCHEMA_DETAILS*/,
            methods: {
                // Redefining of the base method Terrasoft.BasePageV2.onEntityInitialized 
                // which actuates upon the completion of the edit page object schema
                // initialization.
                onEntityInitialized: function () {
                    // The parent implementation of the method is called.
                    this.callParent(arguments);
                    // Calling of the handler method calculating the value for the
                    // [Deadline] field.
                    this.setDeadline();
                },
                // Handler method calculating the value for the [Deadline] field.
                setDeadline: function() {
                    if (!this.get("Deadline") && this.isNewMode()) {
                        var startDate = this.get("StartDate");
                        var differ = 10 * this.Terrasoft.DateRate.MILLISECONDS_IN_DAY;
                        this.set("Deadline", new Date(startDate.getTime() + differ));
                    }
                }
            },
            diff: /**SCHEMA_DIFF*/[]/**SCHEMA_DIFF*/
        };
    });

4. Save the schema.

When the schema is saved and the system web-page is updated, the date complying with the date in the [Start] field + 10 days will be set on the project edit page when creating a new project (Fig. 6).

Fig. 6. – Demonstrating the setup of a computed default value

 

© bpm'online 2002-2018.

Did you find this information useful?

How can we improve it?