woensdag 23 juli 2008

Infopath: "generate" a unique number for your document

Last week I was busy on an infopath form for a sharepoint document library in combination with an approval workflow. I was wondering how to generate a simple, unique number to make sure that my document wouldn't overwrite other documents with the same title.

After a bit experimenting, I came across the following solution:
- Generate a new data connection to retrieve data from a sharepoint document library.
- make sure to select 'ID' from the specified document library
- make sure to get all data, not only the data for the current document.

When storing the document, create a button with the following ruleset:
-Query the data connection that you just created
- insert a function to compute the max(@ID) + 1, this is the highest available ID in the sharepoint lib + 1, so its always unique.
- add it in front or in the end of your title
- save & close ;)

1 opmerking:

Unknown zei

Another option would be writing an event handler on the adding event. If you want to get al ID's you can use a camel query.

I don't know or this solution would be "better". Advantage of an eventhandler is that you can re-use it for non-infopath document templates.

Greetz Nick
www.sharepointdevelopment.nl