Query Forms from within other Forms - Mel Balsamo
in

InfoPath Dev

This Blog

Syndication

Mel Balsamo

Query Forms from within other Forms

You may download the files used in this blog post from this link

Overview

Sometimes you have a form and you want to show another form's data, without actually copying it into your form.

In other words, you don't want to include the queried form into your form. You just want to link the forms together and show the related form as a reference.

How do you add this "satellite" form to your main form without impacting the design of your main form?

In this blog, we'll show you how to query and display data from a separate satellite form without ruining the integrity of your main form.

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 = Policies

Every business process needs a policy. The policy may change throughout the year. For example, an expense report may require receipts for expenses exceeding $100 this year, but this limit may be raised to $150 next year. The business process admin should be able to update the policies by going in to the Policy library and adding/updating forms.

Usage Scenario

View Policy

1.       User opens up your form

2.       Clicks on Show Policy

3.       If no matching policy exists, Main form shows "No policy document"

4.       If policy form exists, Main form queries the policies form

5.       Main form displays the policy

Add or Edit Policy

1.       Business Process Admin adds a new policy with the name for the main form which it will target

Components

To implement, you will need the following:

  • Policies Form - required

  • Policies XTP - generic XTP that can be configured

  • Your Main Form - where you insert the XTP

Technique

Query the Policy form library using the URL for the Main form (as if it is a unique ID to search for a policy).

Here’s how the Policy Form looks like – simple and straightforward.

image1 

Publish your Policy form into your SharePoint library. Submit your business process policies using that form, specifying the Target Form Name, e.g. Expense Report, Leave Request, etc. and entering your Policy text in the rich text field which allows formatting, paragraph breaks, etc.

Here’s an example of a filled-out Policy form:

image2 

There’s also the Policy XTP (template part) that allows easily adding policies into your forms. Here’s how it looks like in the Designer:

image3 

Add the XTP into your InfoPath Designer Custom Controls:

image4 

We will add the Policy XTP into the Expense Report form that ships with InfoPath 2007.

image5 

Follow the steps provided in the XTP – we made it very simple and user-friendly for you! J

Key notes:

  • Make sure to enter the same form name you specified when you submitted the Policy Form. Recall that we submitted policy and gave it a Target Form Name of “Expense Report”

image6

The same name should be specified as the default value in the Policy XTP section’s TargetFormName field:

image7 

  • In the PolicyLibraryUrl field, enter the URL to the library where you published the Policy Form to. Make sure to include the trailing slash, like so:

image8

  • The XTP appended the “_Policy” text in the data connection names so you’ll need to rename the data connection for QdabraRules (only) so that FormsViewer recognizes the commands.

image9

Those are all the changes needed – super easy! J

How the Magic Happens

All the rules are placed in the Show Policy button:

image10 

We use the following commands/technique:

  • ChangeConnectionUrl – to change the URL of the BusinessProcess_Policy XML data connection

image11

We are basically telling our form to get the policy text from the Policy Form library to the form where we added the XTP to, in this case, the Expense Report form.

  • CopyRichText – if a policy has been submitted for our form, we then copy the value from that Policy form into our Expense Report form.

image12

Since we’re copying to and from a rich text field, we use the command CopyRichText in order to keep any rich text formatting.

That’s all there is to it! When you’re done setting it up, publish your form into FormsViewer and test out your changes.

image13 

image14 

Have fun! J 

Comments

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