Skip to main content
Version: 8.1

Enable the automatic numbering of a field on a page that adds records (front-end)

Level: advanced
Example

Enable the automatic numbering of the Code field on the page that adds a product. Use the following numbering pattern: ART_0000N, where N is 1, 2, etc. Implement the automatic numbering in the front-end.

1. Create system settings

  1. Create a system setting that contains the product code pattern.

    1. Click to open the System Designer.

    2. Go to the System setup block → System settings.

    3. Click Add setting on the section toolbar.

    4. Fill out the properties of the system setting.

      • Set Name to "Product code mask."
      • Set Code to "ProductCodeMask."
      • Select "Unlimited length text" in the Type property.
      • Set Default value to "ART_{0:00000}."
  2. Create a system setting that contains the current product code.

    1. Click to open the System Designer.

    2. Go to the System setup block → System settings.

    3. Click Add setting on the section toolbar.

    4. Fill out the properties of the system setting.

      • Set Name to "Product last number."
      • Set Code to "ProductLastNumber."
      • Select "Integer" in the Type property.

2. Create a replacing view model schema of the product 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 "ProductPageV2."
    • Set Title to "Edit page - Product.".
    • Select "ProductPageV2" in the Parent object property.
  4. Implement the automatic field numbering.

    To do this, implement the onEntityInitialized() overloaded base virtual method in the methods property. Called after Creatio initializes the object schema. Call the getIncrementCode() handler method in the onEntityInitialized() method. The handler method assigns the generated number to the Code field.

    View the source code of the replacement view model of the product page below.

    ProductPageV2
    define("ProductPageV2", [], function() {
    return {
    /* The name of the record page object's schema. */
    entitySchemaName: "Product",
    /* 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);
    /* Generate the code if a new element or a copy of an existing element is created. */
    if (this.isAddMode() || this.isCopyMode()) {
    /* Call the Terrasoft.BasePageV2.getIncrementCode base method that generates the number based on the specified pattern. */
    this.getIncrementCode(function(response) {
    /* Return the generated number to the [Code] column. */
    this.set("Code", response);
    });
    }
    }
    }
    };
    });
  5. Click Save on the Designer's toolbar.

Outcome of the example

To view the outcome of the example:

  1. Clear the browser cache.
  2. Refresh the Products section page.

As a result, Creatio will enable the automatic numbering of the Code field on the page that adds a product.


Resources

Package with example implementation