Site icon @WonderLaura

InfoPath: Using the ID field as the Form Filename

Advertisements

STOP USING INFOPATH

It is a common requirement of InfoPath projects to make a form in a form library, where the name of the XML file is the same as the ID of the item itself.  There are several methods I’ve seen out there, and I’m definitely not the first person to blog about this.  One method is in which you create a data connection back to the form library itself, pull in all the items, and calculate the MAX ID + 1, to create your new form name.  That’s an okay method, except that I’ve seen it bomb out once your library view gets to over 1,000 items.

Here’s a way of doing it, which is pretty simple:

  1. Create a field in your form library form, called something like AutoID, as a text field.
  2. Set the default value of AutoID to be the function Now().  Uncheck the box to refresh the value.
  3. Create your submit connection to use the AutoID as the file name
  4. When you go through the publishing wizard in InfoPath, promote the AutoID field up as a column, and check the box to “allow users to edit data in this field…”
  5. Create a SharePoint Designer workflow that runs on create:

    The steps are:
    Wait for field change in current item
    Wait for change in document check out status
    Set field in current item (use the string builder to put the ID field with a .xml next to it)
    Set field in current item (use the field picker to just pick the ID field)

Results: when a form is first filled out and submitted, the filename will be set to a long set of numbers that represents the current date and time.  This is temporary.  As soon as the XML file is first created, the workflow will run, and will change the filename and the AutoID field to the ID of the item.  Then, next time someone opens it up and submits it again (if you want them to be able to-see the checkbox at step 3), it will submit as that same AutoID number.


Exit mobile version