Athento allows you to generate a custom code for a document when it reaches a specific state in its lifecycle. The code is composed of the values of several form fields and ends with the number of an autoincrement-type field. For example: MAD-OBRA12-0005.
To do this, use the Generate custom increment operation, installed in the state in which you want the code to be generated.
Before you start: when the number is assigned
The autoincrement field receives its number when the document is created (when uploading it from the interface, via API, or when creating it from another document), not when it reaches the state. The operation does not calculate a new number: it reads the one the document already has and uses it to form the code.
This means that:
- The code appears in the document when it reaches the state.
- The number follows the document creation order. If some documents never reach that state, there will be gaps in the code numbering.
Requirements
- An autoincrement-type field in the form, with extraction enabled. If extraction is disabled, the field does not receive a number.
- A text-type field in the form where the generated code will be stored.
- The fields that will make up the code (for example, branch office or project) present in the form.
Configuration
1. Install the operation in the space
Install the Generate custom increment operation in the workspace, without phase. This way it only runs when triggered by the state, and not when loading documents.
Configure its parameters:
| Parameter | What to specify |
|---|---|
| List of fields to add | Internal names of the fields that make up the code, separated by commas and without spaces. The order matters: it is the order in which they will appear in the code. Example: delegacion,obra. |
| Separator | Character that separates each part of the code. By default, -. |
| Suffix autoincrement | Autoincrement field whose number will be added at the end of the code. |
| Custom increment field | Text field where the generated code will be stored. |
2. Add the operation to the state
In the form lifecycle configuration, open the state in which you want the code to be generated and add the operation in its operations. Each time a document enters that state, the operation will compose the code.
Verification
Move a test document to the configured state and check the destination field. It should contain the values of the indicated fields, joined by the separator and ending with the autoincrement number. For example: MAD-OBRA12-0005.
Common issues
- The operation returns an error indicating that a field does not exist: check that the names in List of fields to add are the internal names and that there are no spaces after the commas.
- The code ends with the separator (for example,
MAD-OBRA12-): the autoincrement field is empty. Check that extraction is enabled. - The code changes when passing through the state again: the operation recomposes the code each time it runs. If you have modified any of the fields that make it up, the code will reflect the new values. The final number does not change.
More information about the operation: Operation to generate incrementals or custom codes for documents.