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

How to display the difference between dates on edit page fields

Glossary Item Box

Bpm’online uses the capabilities of the standard Date JavaScript‑object to work with dates on the client’s side of the application. For example, the Date.prototype.getDate() method is used to display the day of the month for a specific date in accordance with the local time, and the Date.prototype.setDate() method is used to set the day of the month relative to the current month. All properties and methods of the Date object may be found in the documentation.

For example, when creating a new contract, the [End Date] field should display a date that is 5 days longer than the [Start Day] field. To do this:

1. Create a replacing ContactPageV2 edit page schema of the [Contracts] section. The procedure for creating a replacing client schema is covered in the “Creating a custom client module schema”.

2. Add the following code to the created module:

define("ContractPageV2", [], function() {
    return {
        entitySchemaName: "Contract",
        methods: {
            // The date is set after the object is initialized.
            onEntityInitialized: function() {
                // Checking the mode of the new record.
                if ((this.isAddMode() && this.Ext.isEmpty(this.get("EndDate")))) {
                    // Calling an auxiliary method.
                    this.setEndDate(this.get("StartDate"), 5);
                }
                // Calling the base functionality.
                this.callParent(arguments);
            },
            // Auxiliary method for setting the date.
            setEndDate: function(date, dateOffsetInDays) {
                var offsetDate = new Date();
                offsetDate.setDate(date.getDate() + dateOffsetInDays);
                this.set("EndDate", offsetDate);
            }
        }
    };
});

3. Save the changes.

4. Refresh browser page.

As a result, while adding a new contract. its end date will be 5 days ahead of its start date.

Fig. 1. Case result

NOTE

In order for the date in the [End Date] field to be recalculated automatically when the user changes the [Start Day] field, it is necessary to use the functionality of the computed fields. Please refer to the “Adding calculated fields” article for more details.

© bpm'online 2002-2019.

Did you find this information useful?

How can we improve it?