Archive for Infopath 2007

InfoPath – Get the current user without writing code

Actually the exact same result can be achieved without writing any code. It’s a very common thing to do and I couldn’t find any guide for that, so here it is:

* If you are already familiar with this, this post might still be useful. I have included the complete set of default properties get returned and their proper naming syntax at the bottom.

* This works at InfoPath as well as InfoPath Forms Services.

With InfoPath opened go to Tools > Data Connections, and click ‘add…’ to add a new data connection to the form. This opens up the Data Connection Wizard.

  1. We want to receive data from the WS about the current user, so choose receive data’ and click next.
  2. Our data source is a WS so choose ‘Web Service’ and next.
  3. Now you will have to point the wizard to the WS. Type an address similar to this: http://ServerName/_vti_bin/UserProfileService.asmx  and click next.
  4. Here you get a list of all methods for that WS, choose GetUserProfileByName and click next.
  5. In this screen you can specify what parameters are sent to the method, we are relying on the method’s ability to return the current user name if no value is passed to it, so we will leave this as is (no value is passed to the method) andclick next.
  6. Click next and make sure ‘Automatically retrieve data when form is opened’ is checked.
  7. Finish the wizard.

The GetProfileByName method returns a PropertyData array. You can think of it as a repeating table of name and value pairs.
So Now that you have a data connection that can get the current users, you can use it values. In this example I will show the user’s first name in a textbox.

  1. Add a textbox to the form.
  2. Go to the first textbox’s properties (double click it).
  3. In the ‘Default Value’ part, click the ‘fx’ button next to the ‘Value’ field. this opens up the formula builder dialog.
    vc
  4. Click ‘Insert field or group’.
  5. In the data sources drop down, choose the GetUserProfileByName data source.
  6. Expand all groups under the ‘dataFields’ group, and choose the ‘value’ field. Don’t click OK yet!
  7. With data ‘value’ field selected, click the ‘Filter Data…’ button and ‘Add…’.
  8. In the first drop down (value) select ‘Select a field or group…’ and choose the ‘Name’ field under the ‘PropertyData’ group.

  9. Leave the middle drop down as is (‘is equal to’) and in the last drop down choose ‘type a text…’.
  10. This is the part where you specify which property to put in the textbox. As we said the method returns multiple properties about the user. For this textbox we want to put the user’s first name in, so type ‘FirstName’ (this is case sensitive!). I have included the property list you can use here (just below), so if you want some other property, just type its name instead.
  11. That’s it, all we have to do is to confirm everything so Click ‘OK’ for every open dialog box until you are back in the design mode.
  12. click ‘Preview’ and see the wonder!
  13. If you want more details repeat steps 1-11 and enter different property names in step 10.

Finally, as I Promised, here is the complete list of default profile properties get returned by the userprofileservice. I think they are pretty self explained:

UserProfile_GUID
AccountName
FirstName
LastName
PreferredName
WorkPhone
Office
Department
Title
Manager
AboutMe
PersonalSpace
PictureURL
UserName
QuickLinks
WebSite
PublicSiteRedirect
SPS-Dotted-line
SPS-Peers
SPS-Responsibility
SPS-Skills
SPS-PastProjects
SPS-Interests
SPS-School
SPS-SipAddress
SPS-Birthday
SPS-MySiteUpgrade
SPS-DontSuggestList
SPS-ProxyAddresses
SPS-HireDate
SPS-LastColleagueAdded
SPS-OWAUrl
SPS-ResourceAccountName
SPS-MasterAccountName
Assistant
WorkEmail
CellPhone
Fax
HomePhone

Submitting an InfoPath Form to SharePoint with a Unique Filename

Introduction

InfoPath can be configured to allow users to submit an InfoPath form to a SharePoint library automatically with a unique name and without creating a different file name each time a form is resubmitted.

Summary

The following solution assumes that a SharePoint (MOSS) 2007 or SharePoint Services 3.0 library and an InfoPath 2007 template have been created.

A hidden field is added to the form template. Each form is assigned a unique filename by concatenating field(s) in the form with the now() function. Rules are added to the Submit options to determine whether or not a filename exists, so each time a form is resubmitted, it is not saved under a different filename.

Note: An InfoPath form can be added to SharePoint by assigning a unique filename directly in the Data Connection without using a hidden field or rules, but the use of the now() function will cause the form to be saved under a different filename each time it is resubmitted.

Steps

  • Step 1 – Create a Hidden Field
  • Step 2 –  Add a Submit data connection
  • Step 3 – Add Custom Rules to Submit action
Step 1 – Create a Hidden Field

A hidden field is a field that exists in the data source of the form but is not visible to the user.

The easiest way to create a hidden field is to drag-and-drop a text box control onto the form template’s view. Rename the text box to ‘filename’ and click OK. Then select the filename text box and hit delete to remove the field from the view.

image001.jpg

Step 2 – Add a Submit Data Connection

Go to Tools, Data Connections and click Add. Create a new Connection to Submit data to a SharePoint document library:

image003.jpg

image004.jpg

Enter the document library, and click the fx button and Insert the field ‘fileName’ in order to give the form submitted the name stored under ‘fileName’. Select ‘Allow overwrite if file exists’.

image005.jpg

Give the data connection a name:

image006.jpg

Step 3 – Add Custom Rules to Submit Action

Go to Tools, Submit Options, and click on Rules.

image008.jpg

Add two rules as follows:

  • Rule 1 (fileNameBlank):

    image010.jpg

  • Set condition: filename is blank:

    image012.jpg

  • Set Action 1: Set field’s value filename = concat (Myfield, now()):

    Use field on the form i.e., contactName, followed by the function now() to add the date & time and give the form a unique name.

    image013.jpg

  • Set Action 2: Submit using a data connection (the one created in Step 2):

    image014.jpg

  • Rule 2 (fileNamenotBlank):

    image015.jpg

  • Set Condition: filename is not blank:

    image016.jpg

  • Set Action: Submit using a data connection (the one created in Step 2):

    image014.jpg

You should now have the following 2 rules setup for Submitting Forms:

image017.jpg

Use SharePoint Lists to Create a Filtered Drop Down in InfoPath 2007


Use SharePoint Lists to Create a Filtered Drop Down in InfoPath 2007

Goal: To create an InfoPath form that includes two drop down lists populated from an external source (SharePoint lists) with the result of the first list selection filtering the second.

Scenario: Adventure Works has four types of bikes that they manufacturer:

· BMX
· Mountain
· Racing
· Touring

They have many bike models for each type of bike (Mountain bikes for example are comprised of the following: MX-100, MX-200, MX-220, MX-300, etc.)

Customer service has a form to track issues from customers. They need to select the model from a list but would like to be able to filter the list of bike models based on the type of bike.

Overview of the steps

In SharePoint:

Create a custom list to maintain the bike types
Create a custom list to maintain the current bike models (with a lookup to the Bike Types list)

In InfoPath:

Create a form
Add a drop down list control and connect it to the bike types list
Add a list (or drop down list) control and connect it to the Bike Models list
Set a filter to filter the models based on the selection from the first control

Detailed directions

1. At the top-level site in the site collection (portal.awbikes.local in the classroom environment) create a custom list named BikeTypes

2. Change the ‘Title’ column name to ‘BikeType’

3. Add the following four items to the list: BMX, Mountain, Racing, Touring

clip_image001

4. Create another custom list named ‘BikeModels’

5. Rename the ‘Title’ column ‘ModelNumber’

6. Add a lookup column named BikeType and lookup to the Biketypes list, BikeType column

7. Populate the list with a number of model numbers and choose a type for each
clip_image002

8. In InfoPath, design a new form using a blank template

9. In the Layout task pane add a Table with Title then add a two-column table in the body

10. Resize the rows and columns and hit the tab key a few times to create more rows in the two-column table as follows:
clip_image003

This list will contain many fields including date, customer contact info, issue type, issue description, etc. We are only going to work with the bike type and model fields here.

11. Switch to the Data Source task pane and rename the ‘myFields’ group to CustomerService

12. Under Actions, click Add a Field or Group and add a Text type Field named BikeType
clip_image004

13. Add another text field named BikeModel
clip_image005

14. Drag the two fields into the form
clip_image006

15. Right-click the BikeType control and change to a Drop-Down List Box
clip_image007

16. Right-click the BikeModel control and change to a List Box

17. Double-click the BikeType control and under the section titled List box entries, select the radio button for ‘Look up values from an external data source’ and click Add
clip_image008

18. Select Create a new connection to: and Receive data, Next

19. Select SharePoint library or list, Next

20. Enter the URL of your site where you created the custom lists above (in class, http://portal.awbikes.local), Next

21. Choose the BikeTypes list, Next

22. Select the BikeType field, Next

23. Select ‘Store a copy of the data…’, Next

24. Enter a name for the connection, BikeTypes, select the ‘Automatically retrieve data…’, Finish

25. Click the XPath button for Entries
clip_image009

26. Expand the folders and select BikeType, OK, OK again to finish
clip_image010

27. Preview the form to test the connection to the Bike Types list
clip_image011

28. Close the preview and double-click the BikeModel list control and under the section titled List box entries, select the radio button for ‘Look up values from an external data source’ and click Add

29. Select Create a new connection to: and Receive data, Next

30. Select SharePoint library or list, Next

31. Enter the URL of your site where you created the custom lists above (in class, http://portal.awbikes.local), Next

32. Choose the BikeModels list, Next

33. Select both the ModelNumber and BikeType fields, Next
(you will just display the ModelNumber but you will use the type in the filter below)

clip_image012

34. Select ‘Store a copy of the data…’, Next

35. Enter a name for the connection, BikeModels, select the ‘Automatically retrieve data…’, Finish

36. Click the XPath button for Entries

37. Expand the folders and select ModelNumber, click Filter Data
clip_image013

38. Click Add

39. Set the filter to BikeType, is equal to, Select a field or group…

clip_image014

40. On the Data Source drop-down, select Main, Bike Type, OK, OK, OK, OK, OK already!
clip_image015

41. Preview the form to test the filtering
clip_image016

You can create the filtering using only one list (just BikeModels) by selecting the Show only entries with unique names option. For very large lists this may impact performance.