InfoPath: Using the ID field as the Form Filename


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.



  • Hi Laura, Great workaround and very well written article ! I usually use Max ID+1 to auto numbering. As you mentioned you have seen it bombs out after 1000+ items. Is that because limit of number of items in the view ? I have not seen this issue before so wondering if I need to change those forms to use above method at some point.

  • Bhavesh, Here’s how you can do something similar in 2010 without the “max”: When you create your data connection to get all the items in the library, the data connection wizard will let you choose a sort order. Sort by ID descending. That way, you can look at the value in the ID column and it will automatically show you the highest number, without having to do a max calc.

  • Hi Laura.. I have small question here. Suppose if a form library has one lakh records and now am creating a new record, then is it easy to get the MAX ID value? if we use the receive data connection it will leads some performance issues right.. so tell me the best approach to follow this kind of scenarios…

  • Hi Uday,
    I don’t recommend using this method if you’re having performance issues with the data connection. What I typically do instead of using the ID:
    1. Create a text field called “WhenCreated”.
    2. Set the default value as: translate(now(),”-_:T”,””)
    3. Make your file name contain the WhenCreated column

    it will always be unique.

  • Hi Laura,
    Is there a way to similarly use the ID field as the title field in a SharePoint (2010) list?

  • Pete,
    Sure, you can set the title field as not required, and even hide it from the form (in advanced settings, set to allow the mgmt. of content types to Yes, and then click on the Item content type in your list settings, and change Title to “hidden”)
    Then create a workflow using the action “set a field’s value” and set the Title field to the value of ID.

  • I was looking to make a field a Unique ID but I don’t want it to be the filename. Is it possible to do that in a similar manner as to what is above? And is it possible to have it start at particular # of my choice?

  • No, I don’t know of a way to have a number like that which increments and you can make it start wherever you like.

  • Hi Laura

    I have implemented this workflow and it’s been running for 4 days now. Every time I go back to look at the library’s activity, I find that the workflow has somehow stopped working and that the document name resumes to the now() formula. I then republish the workflow and then it works again. This is very weird and I’m not sure how to rectify the problem – do you have any suggestions?

  • Liza,
    I’m not sure what you mean that it “stopped working”. Did the workflow fail to trigger altogether? Did it give an error? Are you using a browser based form, or are some users possibly using the InfoPath client to open it? Did they workflow stop working on every single item, or did it just fail for some of them?

    • I think I am having a similar issue like Liza. The WF works great when I am the one submitting the form, but when others do it, it “cancels” with this error: “The workflow could not update the item, possibly because one or more columns for the item require a different type of information: Access Denied”

      If I come back and start the workflow manually, it works without any issue.

      The people submitting the form have “Contribute without Delete” access.
      Appreciate any help you can provide.

  • Hi Laura

    Can you take me through on all stages for creating the InfoPath, using ID as file form name, where I create it from, how to link to my sharepoint, creating a data connection library where they will be submitted and how to retrieve, assign the submit button, received etc. I want to create a login and report form for end users,

  • Is there any way to concatenate the current year and the autoID as the filename using your method? So the files would be named 2014-40, 2014-41, 2014-42 etc?

  • I figured out how to add the current year appended to the file name.

    There probably is an easier method but this is what I did.
    Add a text field to the form call it FormCreationDate, set the field to now()
    Add a text field to the form call it CurrentYear
    Create a on-load rule, use Action.
    Condition will be if CurrentYear is blank.
    Under “Run these actions” select the “Set a fields value” action.
    Under “Field” click the button on the right, set the field to CreationYear
    Under “Value” click the button on right, select function substring.
    1st value for substring is the field FormCreationDate, 2nd value is 0, 3rd value is 5, hit okay

    In SPD where Laura sets the name value, change the value using the string builder to CurrentItem:Currentyear (then add a -) then add CurrentItem: ID

    You are just concatenating the value of creation year, inserting a dash, then the value of the ID field.

    Be sure to promote the values off the form when you publish.

  • Hi John, here’s a post where I describe my method for naming files with the date:
    That’s a bit too much for a blog post, but I wrote an entire chapter (9) in my Step by Step InfoPath 2010 book. This book is still relevant because they didn’t change anything in InfoPath from 2010 to 2013.

  • How do you stop infopath 2010 from updating exsiting forms in the library when you update the content type. I have signatures in the forms and each time I update the content type and someone opens an older form it auto updates the form to the new version and removes all the signatures from the old form

  • John,
    I don’t recommend using the out of box digital signatures, they’re just a pain in the butt and useless. There isn’t a way around what you’re trying to do, that I know of. I have written a post on another way that I typically obtain signatures without having to use that functionality.

  • Hi Laura, I have SPD WF that upon creating a new form it sets the field ‘number’ with the form ID# if another field is not blank. The workflow kind of works, meaning that it’s triggered and writes something in the ‘number’ field. But’s it’s not writing the correct thing: It always sets the value as 10, when -for example- the ID# is 2342 (this number can be seen in the SP Document List).
    What I actually need is to set the ID# (or any other unique number with less than 6 digits) in a field inside the form.
    Hope you can help me 🙂

  • Hi Laura,

    I like this post. My company uses SharePoint Online. While using SharePoint Designer 2013 to build the workflow for my InfoPath form, I do not see commands such as you mention in the post (“Wait for” and “Wait for document to be”). How would I accomplish these two parts of your suggested workflow in SharePoint Designer 2013?

    • Hi Allan, those actions don’t exist in SPD 2013. Try it without them, and see how it does. Side note: You’re on SP online, I recommend moving away from InfoPath as soon as possible.

  • Laura,

    Thanks for the prompt response. We’re new to SharePoint Online, so InfoPath forms were our starting point. Two questions:

    1) What flaw in InfoPath or other situation causes you to recommend that we move away from InfoPath forms?
    2) What would technology you recommend that we move to?

    Again, thanks for the help.

Leave a Reply