This is a follow up to an issue that i initially encountered a couple of months ago when we first deployed an Infopath form to SharePoint. The original thread can be viewed here:
SharePoint User Group UKAs Colin pointed out in his comment our approach left us open to the possibility of duplicate records since users could simultaneously open a new form and thereby taking the same last max id from the form library.
Although it appeared to users as though duplication was occuring, in reality the record is not duplicated because SharePoint asigns its own unique ID which automatically increments with each new record.
I have now updated the form as suggested by J_A_G, which also has the advantage of using no code.
This works by applying 2 rules to a hidden field on the form. Documents are assigned a unique filename based on the concat() function by concatenating fields in the form with the now() function. The rules determin whether or not the filename field is blank; if not it is not updated - without these rules each time a form is reopened and resubmitted it would be saved as a new form instance with a different filename as opposed to just updating an existing one.
Here's how to set this up:
- Add a hidden field to the form called 'fileName'
- Create a SharePoint Data Connection to set the InfoPath file name to the hidden field fileName
- Check the box 'Allow overwrite if file exists'
- Open Tools / Submit Options
- Select radio button 'Perform custom action using rules'
- Click the Rules button
- Add Rule 1 (filename is blank)
- Set condition 1: if fileName is blank
- Set action 1: set field's value fileName = concat(myfield, now())
- Set action 2: submit using a data connection: (the DC you created earlier)
- Add Rule 2 (filename is not blank)
- Set condition 1: if fileName is not blank
- Set action 1: submit using a data connection: (the DC you created earlier)