locked
Formula for give me random number in infopath RRS feed

  • Question

  • Hi

    I want to use ID of new item was added to sharepoint list (that customized with sharepoint) as a prosecution code. Can you suggest me some formula to set in properties of text field(that create for show prosecution code to users)in infopath 2010 that give me random number?!

    Thanks.

    Friday, August 31, 2012 8:06 PM

Answers

  • Here's a good way that I usually generate a random number in InfoPath ( I usually use it as the file name)

      • Create a field called "WhenCreated"
      • Put the default formula in it translate(now(),"_-:T","")
      • Then uncheck the box that will recalculate the formula

    This will give you a number that's something like 20120831161115.  It's the year, month, date and time down to the second.  If you need to make it shorter, just use a substring function to only grab a certain number of characters from the end of it.


    Laura Rogers
    Rackspace: SharePoint Consulting
    Blog: http://www.wonderlaura.com
    Twitter: WonderLaura
    Books:Beginning SharePoint 2010: Building Business Solutions with SharePoint
    Using InfoPath 2010 with Microsoft SharePoint 2010 Step by Step

    • Proposed as answer by Hemendra Agrawal Tuesday, September 4, 2012 12:19 PM
    • Marked as answer by Entan Ming Monday, September 10, 2012 3:09 AM
    Friday, August 31, 2012 9:11 PM
  • Hi,

    I understand that you want to use substring with the time you get. You can change the formula that Laura provided like this :

    substring(translate(now(), "_-:T", ""), 2, 3) This will get you three characters from the second position of the Time, that is 012. You can change 2 and 3 in the formula according to your requirement.

    Thanks,

    Entan Ming


    Entan Ming

    TechNet Community Support

    • Marked as answer by Entan Ming Monday, September 10, 2012 3:08 AM
    Friday, September 7, 2012 11:22 AM

All replies

  • Here's a good way that I usually generate a random number in InfoPath ( I usually use it as the file name)

      • Create a field called "WhenCreated"
      • Put the default formula in it translate(now(),"_-:T","")
      • Then uncheck the box that will recalculate the formula

    This will give you a number that's something like 20120831161115.  It's the year, month, date and time down to the second.  If you need to make it shorter, just use a substring function to only grab a certain number of characters from the end of it.


    Laura Rogers
    Rackspace: SharePoint Consulting
    Blog: http://www.wonderlaura.com
    Twitter: WonderLaura
    Books:Beginning SharePoint 2010: Building Business Solutions with SharePoint
    Using InfoPath 2010 with Microsoft SharePoint 2010 Step by Step

    • Proposed as answer by Hemendra Agrawal Tuesday, September 4, 2012 12:19 PM
    • Marked as answer by Entan Ming Monday, September 10, 2012 3:09 AM
    Friday, August 31, 2012 9:11 PM
  • Hi Laura,

    Thank’s for your helpful answer. Can you help me how I can use substring function for remove certain number of characters from the end of it?

    Friday, September 7, 2012 5:06 AM
  • Hi,

    I understand that you want to use substring with the time you get. You can change the formula that Laura provided like this :

    substring(translate(now(), "_-:T", ""), 2, 3) This will get you three characters from the second position of the Time, that is 012. You can change 2 and 3 in the formula according to your requirement.

    Thanks,

    Entan Ming


    Entan Ming

    TechNet Community Support

    • Marked as answer by Entan Ming Monday, September 10, 2012 3:08 AM
    Friday, September 7, 2012 11:22 AM