Peter Gilbert

What’s in a Name?   

Posted by Peter Gilbert | 3 comments 
09Jun2009

One of my main jobs here at UWE is the creation of forms in InfoPath to gather information from users. This data is typically used in SharePoint to initiate a workflow, or may be used elsewhere, in a database. 

When users fill out an InfoPath form, as with any web form, it is useful if you can pre-populate fields for them when the form opens. This saves time and also removes errors than can occur when people are in a hurry, or have lots of data to input. The most common item that people want to automate is filling in their own name when opening a form. Here at UWE we use Active Directory to authenticate users who use SharePoint, and as every user is pre-authenticated before they open the InfoPath form, it should be possible for me get the user’s name from their profile. And indeed it is.

InfoPath has the concept of Data Connections, both for reading data as well as writing data. Data connections can be to SharePoint lists, databases, XML files, or even web services. In this scenario I am going to show you how to query a web service on SharePoint to get the logged in user’s name, and then display it in the form.

First we need the InfoPath form. I am using InfoPath 2007 to create a simple form, this one is based on a template that has been designed by our Marketing people.

image

First I insert a control on the page so that the data has somewhere to go. Some people make the data connections first, I like to make the controls first then add the data later. In the picture below I have dropped  text box control where I want the data to display.

image

Double clicking on the text box control brings up the text box properties box. Here you can give the field a meaningful name, and also set the default value for the text. I have changed the Field Name to txtName for now. We will come back to this Default Value item in a bit after we have set up the data connector.

image

On the menu, under Tools\Data Connections, you can create a data connection for that form template.  Click on Add… to create a new item.

image

Here we are going to receive data. Click on Next. Choose Web Service from the options then Next to continue to the Web Service Details Page. Here I happen to know that SharePoint makes it’s user profile stuff available at http://yourservername/_vti_bin/userprofileservice.asmx?WSDL so that is what I put in the box. Put in the name of your own server here!

data connection wizard

When you click Next you get a wide range of things you can query against. We are going to use GetUserProfileByName.

image

 

When you click Next you need to select the parameter you are going to search against. Here I am using AccountName. I expect you will do the same.

image

Enter a name for the data connection. It helps if you use a name that will make sense to you a year or so later when you come back to make changes!

dcwizard enter name

Here I am using GetUserProfileByName. When you click finish you get a review screen that shows you what choices you have made.

To use the data connector, we go back to our textbox control on our InfoPath form and open the properties box. On the right hand side there is a function editor button. Click on the button to get the insert formula window.

txtbox default function editor

Right, here is where it gets complicated. You cant just copy and paste text into here. This is a dynamic editor that takes values and builds xpath strings. Pasting or typing the text in will not work, you need to click on button then type values.

I want to insert field or group, so I click on the left button. This gives me a choice of data sources. Main is selected by default. You change it here to the source that we just made, GetUserProfileByName.

image image

Now you have to decide what repeating section to use. The section you want is Values:

 image

Now that will not give us a single value. To get the users name we have to filter the data. To do that click on the Filter Data button. Easy innit? Next click on Add… to specify the filter conditions.

 

 

image

Here I know that the value that I want from AD is the PreferredName, so I type in:

image

Clicking OK, then OK, then OK, then OK takes us back to:

image

Then OK again:

image

And again (that's a lot of OK’s) takes us back to the form. Here you can click “Preview” to run up the form and test (you have to be logged in on your domain for this to work. It doesn't work remotely…

image

And there you have it. The currently logged in users Preferred Name automatically appears in the text box. You can use this method to get at other values too, not just this rather easy example.

There are easier ways of getting this information, but this is a good way of learning how to get under the hood of InfoPath to get at data that you might not know is there. Later on I will show you methods that use code in the same way, but that is best left for another time!

tags: InfoPath, SharePoint, web services
Technorati Tags: , ,

bookmark this: Add to del.icio.us Digg it Technorati Facebook Reddit

3 comments for "What’s in a Name?"

Al  Wednesday 10 June, 08.44 

Interesting use of images.

Chris Mills  Tuesday 16 June, 14.23 

test

Stu Dent  Thursday 16 July, 10.36 

Great article

Post your own comment

(will not be published)

(optional)

Verification


All comments will be reviewed before being published
IP addresses and UWE usernames are automatically recorded
Use of this resource is covered by the Acceptable Use Policy

Related articles (automatically generated - external links)

My New SharePoint Blog from Pete Gilbert on 10 Jun 2009lycdfmyv from lycdfmyv on 30 Sep 2009gbsujqhn from gbsujqhn on 30 Sep 2009grhbuell from grhbuell on 16 Oct 2009

trackback URL

See more UWE blogs

u+weAbout this blog

SharePoint evangelist and "developer" working at UWE. I work in SharePoint technologies using C#, InfoPath, Skelta and blog about their good and bad points here. In my "spare" time I am an artist and photographer and help organise the Southbank Bristol Arts Trail as well as running other arts events throughout the year.

RSS Feed Twitter Flickr profile YouTube Channel


Explore by month


Explore by tag

Related links