Enable the automatic numbering of a field on a page that adds records (front-end)
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
-
Create a system setting that contains the product code pattern.
-
Click to open the System Designer.
-
Go to the System setup block → System settings.
-
Click Add setting on the section toolbar.
-
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}."
-
-
Create a system setting that contains the current product code.
-
Click to open the System Designer.
-
Go to the System setup block → System settings.
-
Click Add setting on the section toolbar.
-
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
-
Go to the Configuration section and select a custom package to add the schema.
-
Click Add → Replacing view model on the section list toolbar.
-
Fill out the schema properties.
- Set Code to "ProductPageV2."
- Set Title to "Edit page - Product.".
- Select "ProductPageV2" in the Parent object property.
-
Implement the automatic field numbering.
To do this, implement the
onEntityInitialized()
overloaded base virtual method in themethods
property. Called after Creatio initializes the object schema. Call thegetIncrementCode()
handler method in theonEntityInitialized()
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.
ProductPageV2define("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);
});
}
}
}
};
}); -
Click Save on the Designer's toolbar.
Outcome of the example
To view the outcome of the example:
- Clear the browser cache.
- 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.