HOME ABOUT
I AM HERE
Bookmark and Share

Creating a custom save function for InfoPath 2007 browser based forms

December 8, 2008 14:41 by Aidan

I recently had an issue where it was necessary to only save some of the fields on an InfoPath form back to the form library. To do this required a combination of custom code and submission to a form library using a data connection.

The steps to do this were as follows:

1. Add a Save button to the form

2. Right click the save button and select button properties, change Action dropdown to Submit and click Submit Options...

3. In the submit options select Send form data to a single destination and choose SharePoint document library from the dropdown

4. Click Add to add a new data connection and follow the wizard to set this up to submit your form to the required library

5. Now that the data connection has been set up, select Perform custom action using Code and click the Edit Code button - this will create a submit method in the code behind file

6. In the submit method place the code to do the custom "stuff" and then submit the form to the data connection. The code will look something like:

public void FormEvents_Submit(object sender, SubmitEventArgs e)
{

           //remove values from the form that you don't want to be saved
           XPathNavigator xPnName = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:Name", NamespaceManager);
           xPnName.SetValue("");

           //submit the form using the data connection

           DataConnections["Main submit"].Execute();

           //set e.CancalableArgs to be false once form has successfully saved

           e.CancelableArgs.Cancel = false;           
}

To give the form a unique filename and allow updates to saved forms do the following:

1. Create a new xml node called dtNow, give it a default value of now() and uncheck the Update this value when the result of the formula is recalculated box.

2. Go to Data and Data Connections and Modify the submit data connection created above.

3. In the Filename field add concat(userName(), dtNow) and check the Allow overwrite if the file exists checkbox.

Finally, convert the data connection used to submit the form to be centrally managed as described here


Tags:
Categories: InfoPath | SQL Server
Actions: E-mail | Permalink | Comments (8) | Comment RSSRSS comment feed

Comments

December 22. 2008 17:03

Hi Aidan,

Is it possible to submit the form in a particular folder (dynamically) with the data connection to the SharePoint Library?

Thank you
Chris

Chris

January 27. 2009 00:12

Thank you,

Can we save the data in the form into two lists or document libraries? How?

Basel

April 21. 2009 11:15

great article, thank you!

evden eve nakliyat

April 30. 2009 18:12

Basel - you could try creating a second data connection and submit to this connection as well.

Aidan

August 31. 2009 05:33

Hi Aidan,

Can you tell me the way in which i can publish the
browser enable form which contains code using VSTA.

Kumar

October 7. 2009 22:42

Pingback from sladescross.wordpress.com

Infopath Custom Save « Sladescross's Blog

sladescross.wordpress.com

January 27. 2010 19:22

Thank you.

Is there any way to block updates to data connected fields in saved forms? Currently we have a form set-up and people use the form to submit payment requests and they are saved in a shared drive. However, whenever the database connection for the company field is updated, it changes the saved forms. What can I do to block the updates from the company field in saved forms.

Valerie

January 28. 2010 09:28

Hi Valerie,
I haven't come across this issue before. When you say the saved form is changed when the database connection is changed what do you mean exactly?

My first thought is that if the issue is because the database connection is changed in the saved form (and you want to retain the original connection in already saved forms) you could work around this by creating a new form when the database conenction changes. This would mean the old forms continue to work with the original db connection and any new forms created would use the new connection.

Aidan

Add comment




  Country flag

biuquote
  • Comment
  • Preview
Loading