Hello, I’ve got duplicate code generated when I’m running API workflow on a List. This is my case,
I want to make a workflow for users to create more than one invoice in 1 time. The user just selects the vendors and the items, then the system will create invoices for each vendor. So, the invoice number should be generated automatically with increments in the number.
But the system generated duplicated numbers like this.
The format is current user office code/tag/invoice number/month/year
The invoice number is the total invoice for this office this month +1
as you can see the numbers are only 12 and 15, they should be 12,13,14,15,16,17
My current solution is to set the interval to 2 seconds, but it’s taking too long. I tried to set to 1 second before, but sometimes it’s still duplicated. Is there any better solution?
The issue you’re experiencing with duplicate invoice numbers is likely due to concurrency problems when running the API workflows on a list, leading to multiple processes generating the invoice number simultaneously. This can result in the system assigning the same number to different invoices.
A more reliable solution would be to implement a recursive workflow with an index-based approach. Here’s how you can do it:
Create a recursive API workflow: Start by scheduling an API workflow that processes one invoice at a time instead of attempting to process them all simultaneously. Pass in the required parameters for generating each invoice, along with an index parameter starting at 1.
Select items by index: Use the index parameter to select the relevant vendor and items from the list, e.g., item # index. This ensures that only one invoice is created for the current index.
Increment the index: After each invoice is generated, increment the index and call the API workflow again, but only if index < list:count. This approach ensures that your workflow processes invoices sequentially and avoids concurrency conflicts.
This method will help prevent duplicate numbers, as each invoice will be generated one at a time in a controlled manner, without overlapping. It should be much more efficient and reliable than using a time interval, providing you with the correct sequence of invoice numbers.
I tried to make a recursive workflow before, but my workflow was running without API workflow, I “created a new thing” on the spot, the results were the same. I think there’s some delay in the data. I used “do search” to get the result when generating the invoice number. The next workflow was executed before the first one was finished.