Recently I needed to have simple endpoint that would on each GET generate unique auto-number in specific format that would start from value 1 and would be incremented every time the endpoint is called. In Integray this is quite simple task with endpoint.
Let’s start with task. Inside my task I’ll have one step with the following setup:
Here is Java script that will take Data Checkpoint for current task step. Data checkpoint is saved based on defined output column (in my case AutoNum field of type integer). It is saved every time task is successfully executed.
var AutoNum = 1;
log.info(DataCheckpoint);
if(DataCheckpoint){
AutoNum = DataCheckpoint + 1;
}
var AutoNumFormat = "XM" + ("000000" + AutoNum).slice(-6);
return [
{
"AutoNum": AutoNum,
"AutoNumFormat": AutoNumFormat
}
];
Now that only thing the is need is to create endpoint linked on GET method and defined output:
Here is the result of endpoint:
Attempt 1: [{"AutoNum":1,"AutoNumFormat":"XM000001"}]
Attempt 2: [{"AutoNum":2,"AutoNumFormat":"XM000002"}]
Attempt 3: [{"AutoNum":3,"AutoNumFormat":"XM000003"}]
Important: ensure that Max instances on task is set to 1 so you will always get unique number!