Software Engineer

My photo
Colombo, Sri Lanka
B.Sc.Special(Hons)in IT, MCTS, MCPD, MCP

Tuesday, January 8, 2013

Get Current Users Account Details to InfoPath

Today we'll look at retrieving current users' Information as well as naming the infopath files using the fields on the form.
for the sake of length, I'll divide this post in two part.

In this part, we'll see how to get current users' profile properties in Infopath Browser forms using UserProfileService.asmx

Let's consider an example called Product Request Form where a particular sales employee of the company request for shipment of a particular product

1. First Open the Infopath( this can be done by simply typing 'infopath' in run prompt) and choose a blank template to start with. Make sure you have selected Enable Browser Compatible Features only



2. Add Following Fields to the Main Data source




products: Text
expectedDate: Date
CurrentUserName: Text
IsFormLocked: Boolean
fileName: Text
Error: Text


3. Create the form Layout as below:



Lets insert Some values in the products dropdown:



4. Firstly, we have to get the Current user's name in the Requesting User text box
and the text box be read-only. For this, we will consume the SharePoints' much hyped userprofileservice.asmx's method called GetUserProfileByName

5. For this, go to Design Task -> Data Source -> Manage Data Connections -> Add...
In the Wizard:
a. Choose Create a new connection to: Receive data


b. from the Source of Data, select Web Service


c. In Url, enter your Sites' url follwed by _vti_bin/UserProfileService.asmx


d. Out of the list of methods, choose GetUserProfileByName


e. In Next screen, you'll be asked for Account Name, leave it blank as doing so would get the current User.


f. Make sure in consecutive screens that Store a copy of the data in the form template is unchecked and Automatically retrieve data when form is open is checked

6. In the text box mapped to the field CurrentUserName, we would need to format the display value to that retrieved from UserProfileService.asmx
thats configured to populate its values on form Load. For this, go to Textbox's properties and in the Value field, go to formula builder by clicking fx



7. Click Insert Field or Group.... Choose the secondary receive data source we just created and select value field but don't click Ok yet!!



8. Instead, click on Filter Data... -> Add... to open the filter condition dialog and choose Select a field or group...



9. Choose Name Field again from the Secondary Data Source just created:



10. In the second drop down, select is equal to and in the value drop down, choose Type a Text... and type AccountName



Note: you can choose from a list of profile properties you want:
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


11. Finally, your formula should look something like this:



12. I Guess, this is it, for getting the current users' loginName.. you could have opted for any properties from the list of available properties above.



Original Post by Adil A. Baig.
http://baigadil.blogspot.com/2008/07/get-current-user-for-infopath-and-set.html

4 comments:

  1. Thanks for sharing such informative guide on .Net technology. This post gives me detailed information about the .net technology. I am working as trainer in leading IT training academy offering Dot Net Training in Chennai and i use your guide to educate my students.




    Dot Net Training in Chennai | Dot Net Training in anna nagar | Dot Net Training in omr | Dot Net Training in porur | Dot Net Training in tambaram | Dot Net Training in velachery

    ReplyDelete
  2. Very Informative blog thank you for sharing. Keep sharing.

    Best software training institute in Chennai. Make your career development the best by learning software courses.

    microsoft azure training in chennai
    Docker Training in Chennai
    android course in chennai

    ReplyDelete