Archive

Posts Tagged ‘GetUserProfileByName’

InfoPath forms – Getting the Current Signed In User Without Code

03 October 2012 Leave a comment

Request: Provide a form for users to access on SharePoint… and automatically include the name of the person who is currently signed in.

When we have a request for a form to use in SharePoint, the first tool we go to is InfoPath Designer 2010. Our initial forms using InfoPath forms in SharePoint were quite basic, almost a straight-forward fill in the blanks and let workflow do the rest. But as we learned more about InfoPath and how we could use it with SharePoint Designer workflow in SharePoint hosted forms, we are finding just how powerful and useful these can actually be.

Pulling in the currently signed-in user credentials was something we had not previously been exposed to. To find the solution, we went to Dr. Google and found the solution.

There were a number of articles out there that covered the no-code approach to bringing in the user name into an InfoPath form. A lot of them referred to what I am calling the gold standard article by Itay Shakury. A number of articles reference his work and/or follow the exact same procedure. But this article from April 2007 seems to be an original, which works equally well for 2010 versions of InfoPath Designer and SharePoint.

Solution:

  1. Start a new form in InfoPath Designer

Establish a new Data Connection

  1. From the menu, select “Data Connections” from the Data tab. (This will open the Data Connection Wizard)
  2. Click the “Add” button on the right side of the Data Connection window.
  3. The Data Connection Wizard will provide a few options to choose. Select “Create new connection to:” and “Receive data”, then click the “Next” button.
  4. Choose the SOAP Web Service from which to receive your data and select “Next”.
  5. Provide the URL of the SOAP web service definition. This should be the URL of the site collection with the following appended, “_vti_bin/UserProfileService.asmx?WSDL”  (Example, http://www.contoso.com/_vti_bin/UserProfileService.asmx?WSDL) Click the “Next” button to continue.
  6. Click on “GetUserProfileByName” from the available “Select an operation” choices. Select “Next” to continue.
  7. The next screen of the Data Connection Wizard will ask for parameters to be provided for the connection. Leave the default parameter and click “Next” to continue.
  8. On the following screen, leave the selection to “store a copy of the data in the form template” unchecked and click “Next” to continue.
  9. On the final screen of the Data Connection Wizard, you can leave the default name of the data connection as “GetUserProfileByName” and uncheck the option to automatically retrieve data when the form is opened. Click “finish” to complete the Data Connection Wizard.

Query data on form load

  1. From the InfoPath menu, select “Form Load” from the Data tab.
  2. Add a new rule and call it “GetUserProfileByName”
  3. Create a new text field in your form (name such as “txtCurrentUser)
  4. Add an action that sets the text field’s value to UserName()
  5. Add another action to set the query field of the GetUserProfileByName connection to the text field you created                        
  6. Add an action to Query for Data using the GetUserProfileByName connection

Add the current user field to your form

  1. Add a new text box field to your form.
  2. Edit the text box properties and click the fx button to edit the default value of the field.
  3. On the Insert Formula dialog box, click the “Insert Field or Group” button to select the required field.
  4. From the drop down near the top of the window, Choose the “GetUserProfileByName (Secondary)” field.
  5. Drill down the dataFields until you can select the “Value” field.
  6. With the “Value” field selected, click the Filter Data” button, then the “Add…” button.
  7. In the “Value” drop down field, select “Select field of group” from the menu items
  8. From the pop up window, select “Name” from the PropertyData folder and then click the “OK” button. This will open another Specify Filter window in which you indicate teh field from which you data value will be obtained.                                                      
  9. In the right most drop down field of the Specify Filter Conditions, select “Type text…” and then type in “PreferredName” (no spaces, no quotes).  Leave the middle drop down box as “is equal to”. Select “OK” to save your specification and to close the Specify Filter Conditions box.
  10. To put the solution to test, click the “Ok”s as you work back up from the cascade of windows. Next preview you form and you should see you name displayed in the forms text box field.
  11. To add the a different field, follow the same guidelines as above using the appropriate name of the field.

Below is a listing of the fields that can be returned by the User Profile service:

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

References:

Shakury, I. (2007, April 05). InfoPath – Get the current user without writing code. Message posted to http://blogs.microsoft.co.il/blogs/itaysk/

Garcia Jr., R. (2012, June 21). Auto filling InfoPath forms with current SharePoint user info without code – “Using Web Service”. Message posted to http://smackwagondesign.com/

Melick (member name). (2012, February 17). How to set Current User Name to InfoPath Person/Group Picker. Message posted to http://www.codeproject.com/

Petel, S. (2007, November 20). Importing Data from AD to InfoPath 2007 Form Template (Code free). Message posted to KWizCom SharePoint Blog at http://kwizcom.blogspot.com/