Skip to main content
Search Again

We think these articles could help you:

    See More
    Nintex Knowledge Base

    Incrementing Value with Date and Time Stamp in String Field

    Summary
    How to add an auto incremental value with date and time stamp to a string field in Nintex Form for Office 365 platform.

    Solution

    Option 1

    In the Nintex Form settings configuration page. use the following code in the Custom JavaScript section:
    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

    1. Create a Nintex workflow with a few "Run If" statements that check the length of the ID (1,2,3 or 4 digits).
    2. 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).
    3. 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.
    4. 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.
    So, when creating a new item, the Item ID field  in Nintex Form it will have a default value with the text *Automatically Generated* so this text box should be left as is.
    On Form submitted the above Nintex workflow will start and update the Item ID field in the List column.
     
    • Was this article helpful?