Friday, October 28, 2011

Auto-Generating SharePoint Filenames for InfoPath 2010 on Submit

SharePoint 2010 InfoPath - Auto Generating Filename on Submit Button




1. Create a filename field

Create a strFilename field (Text).  Do not set any conditional formatting, rules, or data validation on this.  Add it to the canvas for now and make it read-only (Fig 1).  This will be visible for testing purposes only. You can hide this if you need to But I left it on my form as I thought it was useful.

 (fig1)


2. Create Submit Data Connection

Create a SUBMIT data connection in your form template that connects to the Form Library where the form resides.  Put in the URL of your Form Library for the “Document Library” field, and choose the strFilename data element for “File name” field by using the fx button.  Check the box for “Allow overwrite if file exists”

In Infopath 2010 this is done by navigating to the "Data" tab, Clicking on "Data Connections", and clicking "Add" as in (Fig 2).

 (fig 2)

then click next and select to submit your data "To a document library on a sharepoint site". Click Next again and specify the location of your sharepoint library where you want the form to be submitted to and also the name of the field that you are going to use as the document title in that library. It is important to remember to use the fx button to select the field to avoid errors see (fig 3).

(fig 3)

3. Disable Save options in the browser

Next the toolbar options for saving in the browser form must be disabled to force the user to use the submit button that we will be creating.
To do this in infopath 2010 the following must be done.

Click on the "Developer" tab, Click on the "language" button and then navigate to the "web browser" settings see (fig 4).

 (fig 4)

Uncheck Save, and Save As (Fig 4) Submit should be grayed since it has not been configured.  If it has been configured, be sure it is unchecked.  Update should be unchecked by default, so leave it.

4.Create the custom Submit button Drag a button control to your canvas and double-click it to get to its properties.  Change the display name to “Submit” or whatever you prefer. We are now going to add some rules to the button which will perform the save logic for us.

Once the button is in position and modified to your liking, ensure the button is selected and click on the "Manage Rules" menu item from within the "Home" tab. This will invoke the rules editor for your submit button.

Click on the "New" drop down box in the rules editor and select "Action"
Change the name of this first rule to "Edit" Click on the hyperlink under the condition label to change the conditions under which this rule will run and set it as per (fig 5)

(fig 5)

Now we need to add the actions that will happen if the conditions in theis rule are satidfied (i.e teh filename is not blank)
Click on the "Add" dropdown next to the "run these actions" label and choose to submit the form as in (fig 6). using the data connection that we created earlier which points to our document library

(fig 6)

Finally for this rule we need to add one last action in the same way except this time we will choose the "Close the form" option. On completion of this rule it should look like (fig 7).

 (fig 7)

In essence this rule will only run if the strFilename variable already has a value (A filename) and simply resubmit the form to the same library with the same name and close the form returning the user to the library Hence the name Edit. If the filename has no value the rule will be skipped.
The second and final rule we need to create is the one that will run if no filename is present (i.e the form is being submitted for the first time)

Create a new rule for the submit button in the same way as we did above except this time the Rule should be named "Submit" and the condition should be set to only fire if the strFilename variable is empty as per (fig 8).

 (fig 8)

we now need to add three actions as we did above but there is an additional action to add first which sets the value of teh strFilename variable to a unique name. Under actions click add, and select "Set A fields value" When the dialog box appears use the fx button to buuild whatever unique filename you like, and apply it to the strFilename variable as per (fig 10).

 (fig 10)

After this action add a submit and close form action as we did for the first rule. The rule should look like that shown in (fig 11) when it is complete.

(fig 11)

In essence this rule will only fire when no filename exists, create a unique filename and submit it to the document library with that filename. Subsequent edits of this form will cause the first rule to fire and resubmit it with its original filename.

If you open or create a form in your SP library now, you will now no longer be able to save using the browser controls, and the submit button will be the only way to do this.







****************************************************************************************
Moss 2007 :
http://claytoncobb.wordpress.com/2009/06/20/auto-generating-filenames-for-infopath-forms/





















Submit Options:












Create  textbox on Infopath form and name it to "strFilename".


 Place the Button on Inforpath path and name it "Submit", click the properties







Click "Submit" on Rules window

No comments:

Post a Comment