Thursday, June 05, 2008

Submit InfoPath forms to SharePoint with unique filenames

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 UK

As 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)

9 comments:

  1. Thats for the information On SherePoint and Share file!
    I stiil dont get it!
    Thank you Again!

    ReplyDelete
  2. Hello

    Your idea is good when I published 1 form to 1 form library (then ID is globally incrementing).
    But how to use this example when I have 20 forms in 20 form library (forms is diffrent).
    I need globally max ID, not locally.

    Arek

    ReplyDelete
  3. Smart move with the filename field value. It ensures data integrity and reduces duplication.

    Now if I can only figure out a clever workaround for my own issue building on top of that.

    Thank you for the idea and help,
    Richard Harbridge

    ReplyDelete
  4. Hi Hannah,

    Great post. Just running into a little problem I hope you can help with. I'm using InfoPath 2003 and was able to make this work, but when I open an existing file, make some changes, and try to resubmit it I receive an error indicating the file is already open by another user.

    Any idea how I can make InfoPath ignore this and submit it anyway? The library doesn't require checkin/out on files so that's not the problem.

    Just wondering,
    Mike

    ReplyDelete
  5. You should enable the Allow overwrite if the file exists in the data connection property

    ReplyDelete
  6. @anonymous
    you should enable the Allow overwrite if the file exists feature in the data connection properties.

    ReplyDelete
  7. hi
    i m getting the messege submit data successfully but it doesnt update the moss list
    any idea pls help me

    ReplyDelete
  8. Very good. I do something similar except my submit option is just the data connection and that's it. I do all the rules on "open" just so I can make sure the form name is assigned soon as it is opened.

    ReplyDelete
  9. Nice. I wanted to use a timestamp (now()) to make a unique filename for the form, but it kept posting new instances of the form. Using the hidden field to keep track of assigned filenames is a nice trick.

    ReplyDelete