Create a Child Form from within a Parent - Mel Balsamo
in

InfoPath Dev

This Blog

Syndication

Mel Balsamo

Create a Child Form from within a Parent

(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.

  1. In InfoPath Designer, open the template named xsn.
  2. 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.

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

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

  1. Add an action that sets the FormName field

  1. Click the fx button and enter the formula: translate(concat(Project, "-", Submitter, "-", now()), ' ~#%&*{}<>:,?\/|"+.…', "_____________________")
  2. Highlight Project and click the button Insert Field or Group
  3. Select the corresponding Project field and perform the same step for the Submitter
  4. Click OK
  5. Add another action rule that Submits Data using the SharePoint Library Submit data connection, and name the rule accordingly.
  6. Save the form and click the quick publish icon  located at the upper left section of your screen to perform a quick republish.
  7. Perform a test submit to verify the submit works – the XML generated will be used for identifying the Processing Instructions of the XML.
  8. 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.

  1. Add the XTP in InfoPath Custom Controls.

  1. 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.

  1. Move the light bulb icon (drag-and-drop) where you want it to appear on your form.

  1. Add data connection that submits to the Suggestion Form library.
    1. Under the Data tab, click Data Connections.
    2. Add a Submit data connection that submits To a Document Library on a SharePoint site.
    3. Enter the URL for the Suggestion Form library.
    4. For the File name, click the fx button and select the node /ns1:SuggestionForm/ns1:FormName from the Suggestion_ Suggestion secondary data connection.
    5. Click Next until you reach the last page of the data connection wizard.
    6. Provide a meaningful name such as SubmitSuggestion, and click Finish to exit the data connection wizard.
  2. Click Submit Suggestion button
    1. Modify Action rule named Insert PIs - set target field to qRules Command node for both actions.
    2. Modify Action rule named Submit to Suggestion Library - set target field to qRules Command node
  3. At the Xtp_Logic_Suggestion secondary data connection, click the node /XtpLogic/Action/SetXMLValues
    1. Modify Action rule name Set Library Name* - set Value to the Library name of the Suggestion Form (not the Expense report form)
    2. Modify Action rule name Set URN* - set Value to the URN of the Suggestion Form
      1. Open Suggestion Form in deign mode
      2. Go to File > Info > Form template Properties
      3. Copy the URN from the ID section
      4. Exit form
  4. Back at the Submit Suggestion
    1. Click the first rule named Set Values.
      1. 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.

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

      3. 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"
      4. 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
  5. Save your final template.

See it In Action!

Now that we have set it all up, we are ready to test our solution.

  1. Publish your form template to SharePoint by creating a new Library (see step 5 for reference).
  2. After Publishing the form, Open a  new document.
  3. Submit a suggestion.
    1. Click on the light bulb icon where you placed it.
    2. The Suggestion box should appear – fill in the fields.
    3. Click on the Submit Suggestion

  1. You should see a link to the submitted suggestion.

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

 

Comments

No Comments
Copyright © 2003-2017 Qdabra Software. All rights reserved.
View our Terms of Use.