sharepointsharepoint-2010infopathinfopath2010

Generate prefix to make 4 digits


I am creating a form that will generate sequential number for report types. Each number is sequential so first report is number 1 and second report is number 2 and so on.

The thing is, the report number needs to be in 4 digits, if the report number is not enough to make 4 digits, fill it in with 0's.

For example: Report 1 number is 0001, report 2 number is 0002, report 10 number is 0010, report 100 number is 0100

I was thinking about adding 4 0's to the report number and do a substring formula, but the problem is I do not know the starting number.

Appreciate the help


Solution

  • I suggest to generate the report number once this is submitted by the user, this way you can get the sharepoint list id number, and then apply a simple set of rules like this:

    Condition:
    
    If Id does not match pattern Custom Pattern: \d{4}
    
    Run this Actions
    
    Set reportNumber's value: result = concat (substring("0000", 1 , 4 - string-length(Id))
    
    Check the box to prevent the next rule to run when the condition is met
    
    Add a new rule under this one just to print the Id if the condition is met.
    

    So this way, numbers below 4 digits will be concatenated, and ids with 4 digits will just be displayed.

    I hope this help you.