Ensuring unique numbers in InfoPath forms

Posted on 2009-05-14
Last Modified: 2012-05-07
I have an InfoPath form that submits to a SharePoint forms library.

The forms are for tracking invoices and include a generated reference that should be sequential and unique.  The number is based on the department and the highest number so far +1.
E.g. invoices generated for Finance, IT, Legal, HR, IT would be
FI000001, IT000002, LE000003, HR000004, IT000005 respectively.

Currently this works fine; when the form is generated it calculates max(ID)+1 from the existing forms, pads the number with zeroes and prefixes it with the department code.

Each department now needs to make their invoices visible only to members of their department (using permissions, a view on a list isn't enough).
The permissions I can do fine using item level permissions in a SharePoint workflow.

Problem is, in the above example, if Legal were to generate a new invoice then the only existing invoice they'd see would be LE000003, so InfoPath would generate LE000004.  Number 4 is in use by HR though.  The next reference should have been LE000006 but InfoPath can't see 4 or 5.

Short of making a separate number fountain I can't think of a way to get around this problem.

Points to either an answer or helpful comments :)
Thanks in advance
Question by:Dhope
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +1
LVL 25

Expert Comment

ID: 24383747
I achieved a fantastic solution to this by using an incemental numbering DB in SQL and connecting InfoPath to it through a web service.
I can give you some detail, but the actual solution itself is being copyrighted subject to being produced for sale.
LVL 14

Assisted Solution

NBSO_ISS earned 100 total points
ID: 24383978
Database solution is definitely the way to go.
We have similar requirements here and using a database solution also allows us to save additional data from the forms that can easily be queried or drawn from the database for reports.

Expert Comment

ID: 24392203
You need to do the increment on the server when the form is submitted and have the form requery the server, get the new ID, and set it in the form. You cna hen concat your 2 char prefix to it and save it.

This topic is the most-often asked question in this forum. I replied to another person last week. There must be at least two dozen forum threads on this. Have you actually tried to search for them?
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.


Author Comment

ID: 24393362

Yes, I searched.  If I haven't found the right link please point me to where it is.

Can't see how simply requerying the library will work.  The form filename must be the same as its reference and InfoPath will not rename a form after it's been submitted.
Also, a SPD workflow fires on any new or modified forms and SPD workflows that update fields in a form have a habit of failing if that form is still open by the submitting user (a scenario that would almost always be the case if the form was still open and being requeried).
LVL 14

Expert Comment

ID: 24394291
I think he is talking about re-querying the SQL database.  The increments would have to be done in SQL and filled into the form.
What you want is a web service that contains a function which goes to the database creates and saves the new ID and returns it to the form.  Once this function is created, in the form, create a connection for receiving the ID.  At submission time, set all of the variables in the connection to values from the form then "Query using data connection".  After the query, you set the ID in the form to the ID returned from the data connection.
If you require further explanation, let me know.

Author Comment

ID: 24394848
Sounds a lot like the number generator described in my question :)  I've set up something using SharePoint lists that achieves a similar (if not as elegant as SQL web service) solution.

At submit time, it creates a new item in a 'NumberGenerator' list (using CAML to submit to a list), refreshes the data connection and use max(@ID)+1 for the next number.
It works with multiple users submitting at the same time and avoids the problem with permissions mentioned earlier.
LVL 14

Expert Comment

ID: 24395007
It is very much the same.  I guess the big difference in this case is you could use SQL to easily differentiate between Finance, IT, Legal and HR.  It is actually very simple to set up.  

Author Comment

ID: 24395085
Current system is only a stopgap, we'll be extending OOTB workflow with K2 Blackpoint in the next month or two.

I'm going to keep one list of numbers, even though they'll be spread over departments.  This is because some departments have the same prefix despite different permissions (e.g. Debt Trading and Debt Syndication will both have DBT for the prefix but wouldn't be able to see each others' invoices).
The prefixes are only really for the benefit of Accounts (who will be able to see everything) but the permissions may be applied more finely than the prefixes.
LVL 25

Accepted Solution

Robbie_Leggett earned 400 total points
ID: 24410387
I decided to write an article which is a step-by-step tutorial to creating a unique, incremental numbering system for InfoPath. It can be found here:



Author Closing Comment

ID: 31581397
Got a solution using an InfoPath only number generator but will certainly use an SQL one soon.
Article will be a big help :D

Featured Post

Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
This article helps those who get the 0xc004d307 error when trying to rearm (reset the license) Office 2013 in a Virtual Desktop Infrastructure (VDI) and/or those trying to prep the master image for Microsoft Key Management (KMS) activation. (i.e.- C…
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

615 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question