I need to generate an ID following this structure "yyyy-xxx" whereas "yyyy" is the current year and "xxx" is an increasing number. This would be easily done with
BUT customer wants to start with "1" every new year... has someone already done this?
Solved! Go to Solution.
I've done something similar for a customer..I've used an additional list that I use as a counter where I have two columns: Title (that stores the year) and Count (that stores last created "custom" ID).
Then, I have a workflow on my main list where I check if in my list exist an element with Title = CurrentYear, if yes, it update the counter and use the new value to create my custom ID like YYYY-CustomCounter, if there is no element for Current Year, it creates an element with current Year and 1 as counter, so next time the workflow will found an element and it can update the value properly.
A possible issue with this approach is if different users create elements at the same time and the workflow that updates the additional list errors because of concurrent updates, but this depends on how the system will be used in your scenario, for my customer a concurrent update is a very rare event so for them it was ok.
I am fairly new to Nintex (so definitely not an expert) but I have recently created something similar to what I think you are after using a WF on item creation to generate a unique ID String for list items in an XX-YYYY-#### format where XX is a set prefix. I haven't used it for very long, so time will tell if it holds up, but here is a rough outline.
Query/collection-sort operations are used on the list to get the greatest ID String.
A regular expression then collection extracts the Year from that greatest string and is converted to a number for comparison later on.
A build string using fn-formatdate extracts the year from the current item's "created" date. It too is converted to a number.
Using set condition, a comparison is done between the current item's extracted created year, and the greatest ID String's extracted year.
If the current item's created year is greater than the greatest ID String's year, the "next" ID number is set to 0001. (This will fire for the first one in the new year)
If not, a regular expression extracts the latest ID number and converts it to a number. A math operation is then used to add 1 to the latest ID Number to create the next number.
A build string is used to put the whole ID String together using the Prefix-The extracted created year-The next number. The ID String field is then set.
I think too, like Giacomos solution there also could be issues if multiple items were created at the same time but given how quickly this runs once started I think at least for my use scenario chances of this happening would be low.
I would be curious if any of the more experienced users see any pitfalls with this approach or have a more streamlined/better method.
This is also how I have done it.
More often, I see people just replace the year and reset the sequential number in the list annually. Which also works. But you gotta remember to do it. Which is the hard part.