Create an XTP to Check In and Check Out forms using UDC files - Mel Balsamo
in

InfoPath Dev

This Blog

Syndication

Mel Balsamo

Create an XTP to Check In and Check Out forms using UDC files

Using data connections in browser-enabled InfoPath form templates introduces some potential issues which can be addressed by using Universal Data Connection (UDC) files. These UDC files extract the data connection information from the form template to handle authentication issues.

According to an MSDN article, using a UDC file located in a data connection library has the following benefits:

  • Form designers can configure form template data connections that will work in both the InfoPath client and InfoPath Forms Services.
  • Form designers can publish a form template to multiple servers and have different data connection settings for each server without modifying the data connection information in the form template.
  • Form designers can publish a domain security form template that can access data sources in a different domain.
  • Administrators can redirect data connections without modifying form templates that reference the UDC file.
  • Administrators can designate which connections are approved for cross-domain access.
  • Administrators can publish data connections on a single server which can be shared across multiple servers.

At the end of this lab, you would have created an XTP that has a UDC file connections to allow checking in and checking out InfoPath browser forms.

In a previous blog post, Hilary stated:

"Before we dive in, I should mention I'm leveraging some functionality that is only available in SharePoint 2010  (and only seems to work correctly in forms opened in the browser) to find out if the form is already checked out".

Also note that this method does not work in Office 365.

The XTP is also available for purchase here. If you'd like to use the pre-made XTP instead of creating it from scratch, make sure to change the data connections to link to the UDC files stored in your own SharePoint server. Contact us at Support (at) Qdabra (dot) com if you encounter any issues.

 

Section 1 – Create a Template Part (XTP) with data connections

In this section, we will create an XTP that will

1.       Open InfoPath Designer to create a blank Template Part.


2.       Create the Check Out data connection.

a.       Go to Data > Data Connections > Add and add a receive data connection to a SOAP Web service.

    

b.      Enter the URL to the Lists web service for your SharePoint server (http://SERVER/_vti_bin/Lists.asmx with SERVER replaced with your actual server name).

If in doubt, test your URL in your web browser – you expect to see a page like this:


c.       Select the CheckOutFile operation:

d.      Note the parameters but leave them blank as we’ll set their values via rules later.

e.      Click Next twice, and in the final window, de-select the checkbox ‘Automatically retrieve data when form is opened, and then click Finish.

3.       Create the Check In data connection.

a.       Repeat everything in Step 2, with the following exception: select the CheckInFile operation.

b.      You should now have two data connections in your XTP:

4.       Add fields in your main data source:

a.       Add a field that will store the form’s file name. Name it FormName and give it a default value that is a concatenated string of the current user’s machine name and the date/time the form is created. The formula would be: concat(userName(), " ", now())

We’ll need to add a rule in this FormName field that removes characters that are not allowed in SharePoint, such as asterisks, brackets, pound signs, etc – any illegal characters should be translated to underscore which is SharePoint’s default naming method. So, select the FormName field and add an action rule (click Manage Rules in the Rules section under the Home tab to display the Rules taskpane) that sets the value of the FormName field; paste this in the formula box: translate(., ' ~#%&*{}<>:?\/|"+.[]…', "____________________")

Your rule should look similar to this:

b.      Add a new field called Message which will be used to inform whether the user has successfully checked out the form or is currently checked out to another user. Display this in a Calculated Value (Expression Box) control on your canvas.

You should now have the following fields in your main data source:

5.       Add a button with rules to check out the form; you can label this button ‘Check Out’.

a.       For your first rule, you are going to add actions that set the values for the CheckOutFile data connection parameters, and then query using that connection.

i.         The first field to set is the is pageUrl:

It needs to be set to the URL of your form's XML file which we’ll determine via the XML’s processing instructions. Paste this in the formula box: concat(substring-before(substring-after(xdXDocument:get-DOM()/processing-instruction()[local-name(.) = "mso-infoPathSolution"], 'href="'), 'Forms/template.xsn"'), my:FormName, ".xml")

If you click on the Verify Formula button, your formula should look like the following:

ii.       Next, set the value for checkoutToLocal. According to MSDN:

Given this information, we'll set that field to the true() function:

iii.      Our final action for this rule will be to query using a data connection -- the CheckOutFile data connection:

Your actions for this rule should be similar to this:

b.      The next action rule will leverage the CheckOutFileResult and provide the user with information.

i.         Add a condition in your action rule:

ii.       Set the value of Message to something like “You have successfully checked out this form.”

Your rule should look similar to this:

6.       Add a button with rules to check in the form; you can label this button ‘Check In’. Similar to what we’ve done before, this button will set the values of the CheckInFile data connection’s parameters:

a.       First, we set the pageUrl field to same formula we used before: concat(substring-before(substring-after(xdXDocument:get-DOM()/processing-instruction()[local-name(.) = "mso-infoPathSolution"], 'href="'), 'Forms/template.xsn"'), my:FormName, ".xml")

b.      You may set the comment field as you see fit – something like "Auto check out and in from form" so that when someone reviews the history it is clear what was going on.

c.       For the CheckinType field, MSDN says:

Those values are referring to minor and major drafts like 1.1, 1.2, 1.3 (minor) and 1.0, 2.0, 3.0 major). At any rate, you may set that field to 0, 1, or 2.

d.      The next action would query the CheckInFile data connection.

e.      Finally, reset the Message field so that it’s blank. (When designing your actual form, you may want to add a submit rule after checking in the form; you don’t need to store any value for the Message field in that case.)

Your rule should look similar to this:

 

Section 2 – Create a Data Connection Library and Convert the XTP Data Connections to UDC

1.       Create the Data Connection Library.

a.       Go to your SharePoint 2010 site > Site Actions > More Options

b.      Select Data Connection Library, give it a name you want, and then click Create.

c.       Note the URL of the data connections library you just created; it will be in the format similar to: http://SERVER/Data Connections/ where SERVER is your actual SharePoint server.

2.       Convert your XTP data connections to UDC.

a.       Back in your XTP in InfoPath Designer, go to Data > Data Connections.

b.      With the CheckInFile data connection selected, click on the Convert to Connection File button.

c.       Enter the URL of the data connection file to be created, e.g.

d.      Convert your CheckOutFile data connection, following the same steps, making sure to name the udcx file accordingly.

At this point, you may now save your XTP (naming it something like ‘Check_In-Out’) and close InfoPath Designer. It may look as simple as this:

3.       Approve the UDC files in SharePoint.

a.       Go to your Data Connections Library in SharePoint and locate the new UDCX files that got added when you converted your data connections earlier. Notice that they are in a Pending state:

b.      Click on the down arrow key (one at a time) and select Approve/Reject.

c.       Select Approve in the dialog that appears, and then click OK.

 

Section 3 – Reusing the UDC in another InfoPath form

This section aims to demonstrate how you can use existing Universal Data Connection files located in your server into your other InfoPath forms. We will create a sample InfoPath form in this section.

1.       Open InfoPath Designer 2010, click Blank Form, and then click Design Form.

Note: If you want to use a data connection file to specify the main data source of a form template, you can use only a file that specifies your Web service connection. To specify the main data source from one of these kinds of connections, click Data Connection File instead of Blank Form, and then proceed to Step 3.

2.       On the Data menu, click Data Connections, and then click Add.

3.       In the Data Connection Wizard, click Search for connections on a Microsoft Office SharePoint Server, and then click Next.

4.       If the site where you created your data connection library is not listed in the Site drop-down list, click Manage Sites, and then click Add to add it to the list.

5.       Select the site where you created your data connection library in the Site drop-down list, expand the name of the data connection library, select the CheckOutFile data connection, and then click Next.

6.       Complete configuring the data connection in the Data Connection Wizard as required for the kind of connection that you have selected (for now, we’d leave all the parameters blank and specify them later on Preview), click Next twice, click Finish, and then disable automatic-retrieve on form open.

7.       You may add one more data connection by repeating the steps above to create connection to the CheckInFile UDC file. When done, close the Data Connection Wizard.

8.       To test, we’ll first drag the data source parameters and the result on the canvas and add a button that queries the data connection, something like this:

9.       Next, we’ll preview the form and fill out the fields to ensure that data is returned upon clicking that button.

a.       For the pageUrl, grab the URL to any existing form in your library, e.g. http://SERVER/MyLibrary/Form1.xml.

b.      checkoutToLocal should be set to true

c.       You may leave the lastmodified field blank

10.   Clicking on the button should mark the ‘Check Out File Result’ box checked. Verify that the form indeed got checked out in your SharePoint library.

11.   You may check the form back in by repeating the steps (the pageUrl and CheckinType fields are required – the latter needs to be set to 0, 1 or 2).

 

Section 4 – Reusing the XTP in another form to control browser edits of forms

This section will guide you through the steps on how you can use the XTP you’ve created in an earlier section into an actual InfoPath form to allow automatic check-ins and check-outs of forms.

1.       Open InfoPath Designer 2010, click Blank Form, and then click Design Form.

2.       In the Controls section under the Home tab, click Add or Remove Custom Controls.

3.       Click Add, select Template Part and click Next.

4.       Browse to the location where you saved the Check_In-Out XTP you’ve created earlier, and click Finish, then Close.

5.       The XTP should now appear in the list of Custom Controls – click on it to add it on your form.

The controls will appear on your canvas and the group/fields should be added into your main data source, like so:

In Data > Data Connections, you will also see the two UDC file connections:

6.       Add a Submit data connection that submits the form to a SharePoint library; use the FormName field as the file name, and allow overwrite if the form exists, e.g.:

7.       Save your form template and publish it to the SharePoint library you are submitting to. From File > Publish > SharePoint server, go through the wizard to create and publish your form in a new browser-enabled form library.

8.       You may now test your form:

a.       Go to the SharePoint library where you published your form.

b.      Add a new document and submit it.

c.      Test the Check Out and the Check In buttons – verify that they work correctly by refreshing the SharePoint library (on another tab or browser window) for each action.

Comments

 

ErnestoM said:

For some reason, whent he XTP is added to an XSN form template, the two rules that set the pageUrl get modified by InfoPath. You'll need to modify the rule in the XSN form template to add this back: xdXDocument:get-DOM()/

January 16, 2013 12:53 PM
Copyright © 2003-2016 Qdabra Software. All rights reserved.
View our Terms of Use.