logo

Automatic process numeration

Creating an enumerator.

An enumerator is a system object that allows configuring automatic numeration.
An enumerator has no graphic interface, but you can create it with a script. To create one enumerator, a creation script must be executed once. Create a separate process for the script and run it in the web part or in the emulation mode, with the Rollback after Execution parameter set to No. After the script execution, you need to know the UID of the created enumerator.
 
Script without using PublicAPI.
Add assemblies:
Elewise.ELMA.Documents
Elewise.ELMA.Documents.Docflow
Namespaces:
using EleWise.ELMA.Documents.Models.Nomenclature;
using EleWise.ELMA.Model.Services;
using EleWise.ELMA.Documents.Managers;
 
Script text:
var numerator = InterfaceActivator.Create<INumerator>();
numerator.Increment = 1;
 //Specify a constant UID, which will be later used for loading; in thie example, Uid = a2797010-8799-4877-bde3-bfc8216c5f49
 //A Uid can be generated with this code: var guid = Guid.NewGuid();
 //Each enumerator has to have Uid
numerator.Uid = new Guid("a2797010-8799-4877-bde3-bfc8216c5f49");
numerator.Save();
 
Creating a similar script with PublicAPI
Documentation on PublicAPI is available here
var numerator = PublicAPI.Docflow.Objects.Nomenclature.Numerator.CreateNumerator(1, new Guid("a2797010-8799-4877-bde3-bfc8216c5f49"));​

Example of using the created enumerator for process instance enumeration.
1. Create a context variable Process Number of the Integer type.
2. Add the variable to the process name template. For this, select Settings - Instance Names in the toolbar and insert the context variable {$Context.ProcessNumber}.
3. As the first process activity, add a script that will calculate the process number.
 
Namespace:
using EleWise.ELMA.Documents.Managers;
Script text:
//Load the required enumerator by UID
var numerator = PublicAPI.Docflow.Objects.Nomenclature.Numerator.Load(new Guid("a2797010-8799-4877-bde3-bfc8216c5f49"));
//Increment the enumerator and write to the context variable. The second parameter specifies whether to save the new value in the enumerator
context.ProcessNumber = NumeratorManager.Instance.GetNewId(numerator, true);