Submit InfoPath Forms to a Form Library With Auto Generated Filename | Quisitive
Submit InfoPath Forms to a Form Library With Auto Generated Filename
December 7, 2009
Quisitive
I’m going to show how to auto generate a file name and provide a form button

Using the default behavior of forms services to save to a document library, the user who is filling out the form would need to click the Save or Save As… button on the InfoPath toolbar and give the file a name.  I’m going to show how to auto generate a file name and provide a form button that will save the form.  This will also work when the form has been re-opened for modification and saved back to the same file.

Step 1 – Create a Data Source Field

The first thing that you will do is create a field to store the filename.  This field will be used by the submit data connection to give the file a name.  It is important to store the filename in the data source so that when the form is re-opened, you don’t generate a new filename, but reuse the already existing filename when saving back to the library.

image

Step 2 – Generate the Filename

The filename should only be generated when the form is new and opened for the first time.  We will create a form open rule to do this.  Choose Form Options from the Tools menu.  Select the Open and Save category on the left and click the Rules button under Open Behavior heading.  Add a new rule with the name ‘Generate Filename’.

image

As mentioned before, we only want to run this rule when the form is new.  To accomplish this we will set a condition for this rule to run.  If the condition is not met, the actions of the rule will not be performed.  In this case, we want to test for the absence of a value in our Filename data source field that we created in step 1.  Only if a value is not present will we generate a new filename and save it to this field.  To do this click, Set Condition… and only run the rule when Filename is blank.

image

Once the condition has been set, we must specify the action.  We need to set the value of the Filename field to our generated filename.  In this example, we will create a filename with a prefix of “MyForm” and place a date/time stamp at the end of the name.

image

Step 3 – Create the Submit Data Connection

Now, we are going to create a data connection that will be used to save the form to the library and use the Filename field to give the form a filename.  Go to the Tools menu and select Data Connections…  Now click Add… to create a new connection to submit data to a document library on a SharePoint site.  When prompted for the File name, click the fx button and insert field of group and select the Filename field in the data source.  Also, make sure that the Allow overwrite if file exists option is selected.  Finally, name the connection Submit.

image
image
image
image

Step 4 – Create the Submit Button

Now, add a new button onto the form’s design surface.  Double-click the button to open its properties and click the Rules button.  We are now going to create a rule to submit and close the form when the button is clicked. Create a new rule named ‘Submit and Close’ then add a new action to Submit using the Submit data connection and another rule to close the form.

image
image
image
image

Summary

What we did was create a field value that will be used to contain the filename and will become part of the forms data source so it can be used on any subsequent opens and saves of the form.  Then we configured the button to use a data connection that uses the field value that contains the filename to save the form to a SharePoint form library using the filename field value every time the form is saved.