(Click here to download the files used in this blog post.)
Overview
When you're designing a form, you don't need to include "everything but the kitchen sink”. I confess abusing this idiom in the past. It means "almost anything one can imagine". I have used "kitchen sink" as a metaphor for an InfoPath form from hell that has everything thrown into it. Visually, I imagine a kitchen sink so full that it is impossible to wash the dishes.
It's easy for a form to become bloated and unwieldy.
For example, imagine that you have a simple Expense Report form that submits to a SharePoint library. Good job! You publish and people start using it and they are happy for a month or so. Then, you get a feature request to add a simple approve-request workflow. So, you add a "Change History" section to your form (we have an XTP for this) and promote properties for the last modified user and date-time fields to integrate with a new SharePoint workflow. This makes sense because you can now measure the time between submit and approval or rejection and resubmit, etc. You can't do that with SharePoint workflows, so it makes sense to add this repeating block to your form. Fine. Another month goes by and somebody wants you to add a Expense Policy to the form. Now, you know that there are many business policies in your org and during a slow Tuesday afternoon you daydream of creating a general form for policies and linking them together but then when Wednesday rolls around, you're slammed with other work and you just don't have time to do that so you hard-code the policy into the form and that gets the job done, but you know you'll have to republish with every update. Let's hope the policy doesn’t change often. After another month and yet more feature requests and suggestions, you finally put your hand to your head and in a flash of insight realize that whack-a-mole is the wrong game for you. Instead, you will design a place in your form where users can submit suggestions. You will automate the task of improving your form and in the process get control of your work week back. You will schedule one time every two weeks to review form feedback and schedule changes. Life will be orderly. Only one problem: how to extract suggestions saved in the Expense Report form…
Here's where it makes sense to have two dishwashers. You've got one for glass stemware and another for pots and pans. Different cycles for different dirtiness. Your Expense Report form and Suggestions will be in different libraries. The Expense Reports need to be processed quickly. The suggestions, not so much. OK, that's the idea, but how to extract the latter suggestion from the former expense report and yet still give people a "ticket #" so that they feel like their suggestion didn't end up in the black hole of SharePoint?
With Qdabra's easy-to-inject Suggestions XTP, you can add a Suggestions section to your form and have it saved to a separate library.
Requirements
- You are a site collection admin.
- Your site has the FormsViewer App installed, or your SharePoint admin can install it.
- You have an InfoPath form or access to InfoPath Designer to create one.
Sample Scenario = Add a Suggestion Box to your form
Adding a Suggestion Box to your form is a great way to capture feedback, and defuse negativity of a new process. If someone calls to say there's a bug, you can have them enter it into the suggestion box right away and promise them some turnaround. They're happy you listened.
qRules has a command called SubmitToSharePoint which users to create a different XML document and submit to a SharePoint form library. It supports “create” and “update” actions for XML fragments based on an XML mapping.
How it Works
This lab provides a Suggestion form and a Suggestion template part (XTP). If you open both in InfoPath Designer and compare the Suggestion form’s main schema against the XTP’s Suggestion secondary data source schema side-by-side, you’ll see that the XTP contains the schema of the Suggestion form.
Suggestion Form:

Suggestion XTP:

When you add the Suggestion XTP into your form, the XTP will add the schema as an XML to the secondary data source.
Design the Form that Submits Suggestions
For your convenience, we are providing a sample form template that you can start with. You will continue designing this form as if it’s one of your company’s solutions.
- In InfoPath Designer, open the template named xsn.
- Add your fields and controls – you can add any field you want; but for the purpose of this exercise, we’ll add fields for Suggestion, Project, Submitter, and FormName; and use text box controls on the canvas.

- Publish the form to a Library.
- Click File → Publish → SharePoint Server.
- Enter the training site URL (https://training2013.formsboard.com/MastersCourse/). Click Next.
- Select Form Library and click Next.
- Select Create a new form library and click Next.
- Enter a unique name for your form library. For example, <YourName>_Part12_Lab1.
- Click Next twice and Publish.
- Add your Submit and Close buttons

- Create a Submit to Library data connection
- Under the Data tab, click Data Connections.
- Add a Submit data connection that submits To a Document Library on a SharePoint site.
- Enter the URL for the library created in step 3.
- For the File name, click the fx button and select the FormName
- Click Next until you reach the last page of the data connection wizard.
- Leave the SharePoint Library Submit name as is, and click Finish to exit the data connection wizard.
- Double click the Submitter field, click the fx button, and enter the formula userName().
- Click on the Submit button.
- Under the Home tab, click Manage Rules.
- Add an action rule named Generate FormName.
- Click the Condition
- For the first dropdown, select the FormName
- Select “is blank” from the second dropdown.

- Add an action that sets the FormName field

- Click the fx button and enter the formula: translate(concat(Project, "-", Submitter, "-", now()), ' ~#%&*{}<>:,?\/|"+.…', "_____________________")
- Highlight Project and click the button Insert Field or Group
- Select the corresponding Project field and perform the same step for the Submitter
- Click OK
- Add another action rule that Submits Data using the SharePoint Library Submit data connection, and name the rule accordingly.
- Save the form and click the quick publish icon
located at the upper left section of your screen to perform a quick republish.
- Perform a test submit to verify the submit works – the XML generated will be used for identifying the Processing Instructions of the XML.
- Download the generated XML and save it on your desktop or downloads folder.
Add the Suggestion XTP
You will then add the Suggestion XTP that will allow suggestions to be submitted into the target Library we created earlier.
In this section, you may use any form you wish to use but for purposes of training, a QdExpenseReport-Sample pre-injected with qRules form has been provided.
Note that qRules is required. You may need to inject your form with qRules if you are using a different form.
- Add the XTP in InfoPath Custom Controls.

- Drag the Suggestion XTP on your form canvas.
This is how the XTP looks like on the design canvas:

In your Fields task pane, notice that the XTP added groups and fields into your main data source.

If you go to Data > Data Connections, you will see that the XTP also added data connections:

And if you select the Submit Suggestion button then display the Rules task pane via Home > Manage Rules, you’ll see the pre-configured rules:

These are just some of the benefits of using XML Template parts (XTPs) – it adds almost everything for you; in short, you let the XTP do the hard work. Another huge plus is that you can use XTPs in as many forms as you want.
Modify the XTP
We will make a few modifications to the Suggestion section so that it meets our form’s needs.
- Move the light bulb icon (drag-and-drop) where you want it to appear on your form.

- Add data connection that submits to the Suggestion Form library.
- Under the Data tab, click Data Connections.
- Add a Submit data connection that submits To a Document Library on a SharePoint site.
- Enter the URL for the Suggestion Form library.
- For the File name, click the fx button and select the node /ns1:SuggestionForm/ns1:FormName from the Suggestion_ Suggestion secondary data connection.
- Click Next until you reach the last page of the data connection wizard.
- Provide a meaningful name such as SubmitSuggestion, and click Finish to exit the data connection wizard.
- Click Submit Suggestion button
- Modify Action rule named Insert PIs - set target field to qRules Command node for both actions.
- Modify Action rule named Submit to Suggestion Library - set target field to qRules Command node
- At the Xtp_Logic_Suggestion secondary data connection, click the node /XtpLogic/Action/SetXMLValues
- Modify Action rule name Set Library Name* - set Value to the Library name of the Suggestion Form (not the Expense report form)

- Modify Action rule name Set URN* - set Value to the URN of the Suggestion Form
- Open Suggestion Form in deign mode
- Go to File > Info > Form template Properties
- Copy the URN from the ID section
- Exit form
- Back at the Submit Suggestion
- Click the first rule named Set Values.
- Modify the value of the action that sets the Project field to a value you desire – this should correspond to the current form you are adding the submit suggestion xtp to.

- Modify the second rule named Insert PIs.
- Open the XML saved in step 21 using a text editor such as notepad.
- On the first action, update the corresponding values for the following Processing Instruction attributes:
- solutionVersion
- productVersion
- PIVersion

- On the second action, verify if the values for the /data parameter are the same. If not, update the attribute values accordingly
- InsertPi /dsname=Suggestion_Suggestion /name=mso-application /update=true /data=progid="InfoPath.Document" versionProgid="InfoPath.Document.3"
- Double check the /dssubmit parameter value – make sure that the value is the same as the Submit to Library data connection name create in step 25 g. By default this should be: SubmitSuggestion
- Save your final template.
See it In Action!
Now that we have set it all up, we are ready to test our solution.
- Publish your form template to SharePoint by creating a new Library (see step 5 for reference).
- After Publishing the form, Open a
new document.
- Submit a suggestion.
- Click on the light bulb icon where you placed it.
- The Suggestion box should appear – fill in the fields.
- Click on the Submit Suggestion

- You should see a link to the submitted suggestion.

- Click on the link to open the Suggestion form that you just submitted.
