Auto-number formatting with leading zeros - InfoPath Dev
in

InfoPath Dev

Auto-number formatting with leading zeros

Last post 11-13-2009 02:09 AM by Svetoslav. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 04-03-2009 11:29 AM

    Auto-number formatting with leading zeros

    I'm trying to create auto number with leading zeros but it's not quite working. the format i want is "LR-DP-0001", with the number incrementing like 0010, 0110, 1110. Currently the code i'm using is: concat("LR-DP- ", max(@ID) + 1). I don't know how to do the leading zero. Help?

  • 04-03-2009 05:38 PM In reply to

    Re: Auto-number formatting with leading zeros

    Hmmm. I'm not sure if there is a formulaic way to pad a number with zero in InfoPath. Is this formula in a default value? Or a rule? In a rule, you could set conditions, like if max(@ID) + 1 is less than 10 use the formula concat("LR-DP- 000", max(@ID) + 1) and if max(@ID) + 1 is greater than 9 but less than 100 use the formula concat("LR-DP- 00", max(@ID) + 1)  and so forth... but if you are using a default, you'd have to try to make the default conditional. There are ways to do that (see this post) but they can get rather complicated...

    Hilary Stoupa

  • 04-04-2009 05:10 AM In reply to

    Re: Auto-number formatting with leading zeros

    The formula is a rule and I was able to create the conditions but it doesn't work because the submit button only works with one data connection. I tried to create multiple data connections based based on the number of rules but it still doesn't work. when i submit, it says the form is submitted succesfully but nothing shows on the front end. What else can I can? Thanks
  • 04-10-2009 08:04 AM In reply to

    Re: Auto-number formatting with leading zeros

    Sorry for the delay on getting back to this thread! I'm confused as to what multiple submits have to do with this? At any rate, you can submit using rules, and set up multiple submit data connections and use rules and conditions to choose which connection to submit with. What do you mean by 'nothing shows on the front end'? Where are you submitting to?

    Hilary Stoupa

  • 11-13-2009 02:09 AM In reply to

    Re: Auto-number formatting with leading zeros

    Hi dalmeidd,

     it will be very easy if you apply some Jscript code. It will not include more than 10 lines. If you haven't solved the problem here is a very simple code how do it:

     

    XDocument.DataObject["Data connection name"].Query;

    var objList = XDocument.DataObjects["Data connection name"].DOM;

    objList .SetProperty(".....")

    var nodes = objList .selectNodes("here is the dfs path\@ID");

    maxID = nodes.Math.Util(nodes)

    uniqueID = maxID +1;

    while ((uniqueID.toString()).length <number of length you want )

    {

    uniqueID = "0"+uniqueID;

    } 

     

    This is a very fast example so there can be some errors. But the idea is correct. Hope you get it fast.

    Regards,

    Svetoslav

Page 1 of 1 (5 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.