TOPIC
How to add an auto incremental value with date and time stamp to a string field in Nintex Form for Office 365 platform.INSTRUCTIONS
Option 1
In the Nintex Form settings configuration page. use the following code in the Custom JavaScript section:
Note: The ItemIDStock is a text box control, with a JS client Id with name : JSidItemIDStock (go to the text box control settings page and under Advanced section : Client ID JavaScript variable name : JSidItemIDStock
NWF.FormFiller.Events.RegisterAfterReady(function () { var oldValue = NWF$("#" + ItemId).val(); var length = oldValue .length; var appendStrzeros= new Array(7 - length ).join("0"); // Get current date var date = new Date(); // Format day/month/year to two digits var formattedDate = ('0' + date.getDate()).slice(-2); var formattedMonth = ('0' + (date.getMonth() + 1)).slice(-2); var formattedYear = date.getFullYear().toString().substr(2,2); // Combine and format date string var dateString = formattedMonth + formattedYear; // format AJGXXXXXX-MMYY var idStockformat = 'AJG'+ appendStrzeros + oldValue + '-' + dateString; NWF$("#" + JSidItemIDStock).val(idStockformat ); });
Note: The ItemIDStock is a text box control, with a JS client Id with name : JSidItemIDStock (go to the text box control settings page and under Advanced section : Client ID JavaScript variable name : JSidItemIDStock
So that the NEW item will always have the value : AJG000000-MMYY when Adding new item. but it will adjust itself when Edit item.
Option 2
- Create a Nintex workflow with a few "Run If" statements that check the length of the ID (1,2,3 or 4 digits).
- Based on the result it will build a string to match the ID, ensuring the digit range does not exceed 6 digits. (i.e. AJG000001, AJG000100 etc).
- Then using "Regular expressions" to extract the Month & Year from the ‘Created’ date, then stripped the first two numbers from the Year (YYYY become YY), the last regular expression removes any special characters. This will give date format as MMYY as required.
- Then add "Build string" action" to build another string combining the reference number provided from the Run If statement and the MMYY from the regular expressions which updates the Item ID list column accordingly.
On Form submitted the above Nintex workflow will start and update the Item ID field in the List column.