?
Solved

get the email ID from AD

Posted on 2009-04-14
31
Medium Priority
?
850 Views
Last Modified: 2012-05-06
I have a infopath form where I have the Prefered Name of employees from AD in a Dropdown List.(Manually added)
I have one more text box in the infopath , this text box value should be the value of the corresponding employee's email ID from AD populated dynamically based on the value from Prefered name Dropdown.
I'm using infopath 2007.
Thanks in advance!
0
Comment
Question by:agcps
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 15
  • 15
31 Comments
 

Author Comment

by:agcps
ID: 24143967
Adding to my Question, I would like to inform that its a browser enabled form, that is published on a sharepoint site
0
 
LVL 21

Expert Comment

by:66866
ID: 24147461
You will need to write an AD Query to retrieve the email address based on the User's CN (Common Name). Are you familiar with writing AD queries?
0
 
LVL 25

Expert Comment

by:Robbie_Leggett
ID: 24147581
Set up a data connection in the InfoPath form. Make it a webservice connection and use it to RETRIEVE data. Then type in the following URL:

http://(yoursitename)/_vti_bin/userprofileservice.asmx

This will give you access to all of the AD tools from within InfoPath and also works in browser enabled forms.

:-)
0
Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

 

Author Comment

by:agcps
ID: 24148606
Hi,

I'm already using the above web service and retriving PreferedName from AD.
My requirement is based on this preferred name in Dropdown I want to get the respective emailId from AD.
0
 
LVL 25

Expert Comment

by:Robbie_Leggett
ID: 24148650
Then create a filter specifying
textbox value = emailid
where
PreferredName = dropdown box
 
:-)
0
 

Author Comment

by:agcps
ID: 24154764
But how can I do as in the Dropdown I was actually hardcoding the Preferred name of all the managers.
I'm not sure how to get all the managers from AD to infopath dropdown. So I'm copying the PreferredName from User profile and adding manually all the managers to the infopath Dropdown.

Now is there a way to get the manager list using the above webservice or any other way into the infopath dropdown.
Also let me know how can I filter based on dropdown values to get the respective email ID from AD
0
 
LVL 25

Expert Comment

by:Robbie_Leggett
ID: 24155299
Do you just need the one manager for the person filling in the form? If so, the webservice should give you that aswell as the emailid, using the formula above.
 
:-)
0
 

Author Comment

by:agcps
ID: 24155338
not one manager
In dropdown I want all managers, Hardcoding of preferredname in Dropdown is also ok.
But what i need is based on the selection in Dropdown, the respective emailid of that person dhould come from AD
0
 
LVL 25

Expert Comment

by:Robbie_Leggett
ID: 24155455
It would be a lot easier if you needed the manager of the currently logged in user that is accessing the form. :-)
 
Is this not an option?
 
:-)
0
 

Author Comment

by:agcps
ID: 24157486
Thanks Robbie, I already used that in other forms, but this requirement doesn't suit with it.

Let me know how we can do this,

In dropdown I want all managers, Hardcoding of preferredname in Dropdown is also ok.
But what i need is based on the selection in Dropdown, the respective emailid of that person dhould come from AD

0
 
LVL 25

Expert Comment

by:Robbie_Leggett
ID: 24157689
If you hardcode the preferredname into the dropdown, you should then be able to create a rule on the dropdown which sets the value of the emailID in the text box.
 
It will get the emailID from the userprofileservice web service, by passing the hardcoded preferredname into the value parameter of the webservice. This would then return the emailid from the web service.
 
:-)
0
 

Author Comment

by:agcps
ID: 24158352
Let me know the steps to do the above.

Thanks a lot in advance
0
 
LVL 25

Expert Comment

by:Robbie_Leggett
ID: 24158512
Here is an excellent guide with pictures etc:
 
http://kwizcom.blogspot.com/2007/11/importing-data-from-ad-to-infopath-2007.html
 
:-)
0
 

Author Comment

by:agcps
ID: 24158703
yes, I have already did many forms using this way.
But here I'm not sure how to get email ID from AD based on selection in the dropdown.
can you tell me how I can go ahead in this case.
0
 
LVL 25

Expert Comment

by:Robbie_Leggett
ID: 24158882
After you have populated the name field in the example, you just need to create a rule that fires from the name box which sets the value of the email ID field.
 
Specify that:
EmailIDBox = EmailID (Filtered to where PreferredName = .)
 
:-)
0
 

Author Comment

by:agcps
ID: 24165471

I tried but didn't get the way to do this.
Can you give me the steps
0
 
LVL 25

Expert Comment

by:Robbie_Leggett
ID: 24165814
Step 1: Create a blank form template

1. Click file->design a form template



2. Select Blank


3. Click OK




Step 2: Setting up the web service connection
 
1. Create a new data source connection.
 
Go to tools >Data connection



2. In the "Data connections dialog Click on Add



3. Select create a new connection to - Receive data Click next



4. Select Web service as the source type



5. Insert the Following web service name: http://<servername>/_vti_bin/userprofileservice.asmx?wsdl


6. Replace <servername> with your SharePoint server name and click next

7. From the operations drop down list select GetUserProfileByName



8. In MOSS, calling this operation without sending a user name will return current users profile.
 
9. Click "next" keeping the defaults in every screen until you can hit Finish





10. Close the Data connection window.




Step 3: Viewing and choosing the AD details we wish to import:
 
Now, we need to insert the AD information to the correct fields. To do so, we first need to see what kind of data we can use.

Since the users profile may include different properties according to your organizations' software and other dependencies, the web service results returns a set of name-value collection that we can use in order to get the results we need.
So  first, we have to find the name of the property and then we'll use it to get its value from the web service.


Here is how it is done:
 
1. To see all the available fields click on View -> Data source


2. In the Data source drop-down select the one we just created.

 

3. Expand the DataFields container node and select the following fields in the results:


4. In the drop-down menu on the selected nodes select "repeating table" and place it in the form.
 
5. You now have a repeating table with all data returned by the web service. To see all the AD fields available to you, Click "preview" in the tool bar.


6. Now, locate the property you need and copy its name


7. Return to the design mode by clicking "close preview".
 
 
Step 4: placing the AD details in the controls:


Now the only thing left for us to do is place the field we chose earlier (in step 3) and define the control to show that fields info.
 

1. In the form, double-click the control you wish to fill

 
2. In the control properties click on to open the function editor
 


 

3. Then click on "Insert Field or Group".

 

4. In the next window, select the data source you created


5. Expand all the folders under "DataFields" until you can see and then select the "Value" node.
 
6. This inserts one of the values we got in the web service response. Now we need to enable it to filter the values by the property name we want. To do so:

7. Click on "Filter Data" button. In the pop up window click "Add"


8. In the next window select the following options


9. And select the Name node from our service data source:



10. Click "Ok". Then Select "Type Text" and enter the property you copied in the previous section as the value


11.Click "Ok" to confirm and close all the pop-ups.

12. Click "Preview" in the tool bar to see the results.




 
Now your form displays the user preferred name as it was entered in the AD and all that without writing a single line of code!

Important:
Your document must be fully trusted in order to execute the web service correctly. To do make sure they are, please check the "Tools-Forms Options" form security options.
 
:-)
0
 

Author Comment

by:agcps
ID: 24165888
Hi,

All these steps are fine.
EmailID Property is WorkEmail

Now I have a Dropdown having PreferredName of few users from AD, this is Hardcodded in Dropdown.
ok now, on selecting a preferredname from Dropdown, the corresponding emailId of the person choosen from Dropdown should get updated in a textbox.

On form we have say  1. "PreferredName" --> dropdown.
                     2. "emailID"       -->   Textbox
0
 
LVL 25

Expert Comment

by:Robbie_Leggett
ID: 24165939
Then you need to add to the rule on the preferredname box.
 
You need to set a value.
The value is the query field of the ad data connection.
Pass it the preferredname from the dropdown.
Then use the filter I posted about 10 posts back and you should get the emailID of the person in the dropdown.
 
The key is to pass the preferredname into the query portion datasource, otherwise it will give you the person who's currently logged in details.
It says this in the example I provided.
 
:-)
0
 

Author Comment

by:agcps
ID: 24166259

I always get the currently logged in user EmailID only.
How to pass the preferredname into the query portion of datasource

Steps im did is

"Preferredname" Dropdown properties

rules-->add-->add action-->set the fields value -->
field --> main datasource -->EmailID
value -->fx-->insert field or group -->getuserprofilebyname -->valuedata/value -->filterdata-->ADD-->select a field or group -->getuserprofilebyname -->propertydata/name -->is equal to -->workEmail --> ok till all windows close

0
 
LVL 25

Expert Comment

by:Robbie_Leggett
ID: 24166327
First you need to do this:
rules-->add-->add action-->set the fields value -->
field --> AD datasource -->Value (set the value as the dropdown)
 
Then run the second rule:
 rules-->add-->add action-->set the fields value -->
field --> main datasource -->EmailID
value -->fx-->insert field or group -->getuserprofilebyname -->valuedata/value -->filterdata-->ADD-->select a field or group -->getuserprofilebyname -->propertydata/name -->is equal to -->workEmail --> ok till all windows close

 
:-)
0
 

Author Comment

by:agcps
ID: 24166481
Thanks alot, But still I'm not able to get it. Only the login user email Id is coming.
Please give me still further step by step approach.
The fields I'm using is,
"PreferredName" --> dropdown.(preferrednames are hardcoded)
"emailID"       -->   Textbox
0
 
LVL 25

Expert Comment

by:Robbie_Leggett
ID: 24166808
First you need to do this:
Pass the value of the dropdownbox to the query parameter of the AD datasource by doing this:

rules-->add-->add action-->set the fields value -->
field --> AD datasource -->Value (set the value as the dropdown)
 
Then the datasource will return a value based upon the drop down value whicj can be rerieved using:
 
rules-->add-->add action-->set the fields value -->
field --> main datasource -->EmailID
value -->fx-->insert field or group -->getuserprofilebyname -->valuedata/value
 
:-)
0
 

Author Comment

by:agcps
ID: 24167279
In the first step, I didn't get these

AD datasource -->Value (set the value as the dropdown

what is this AD Datasource, are you refering to getuserprofilebyname, datasource

In rules:

Action:
Set a fields value

Field:

"AD datasource" -->I didn't get this

Value:
"(set the value as the dropdown)" --> I didn't get this too

Second step is clear
0
 
LVL 25

Expert Comment

by:Robbie_Leggett
ID: 24167360
In the first rule you need to set a fields value. The value you need to set is in the userprofileservice data connection. When you expand this, you have 2 trees. One of them is the queryfields. You need to pass the value that's in the dropdown to the accountname field.
 
See the attached picture.
 
This will allow you to get the emailid of the person in the dropdown and display it in the second box by running a second rule which filters the userid from the data connection based upon the dropdown box.
 
:-)

setusername.jpg
0
 
LVL 25

Accepted Solution

by:
Robbie_Leggett earned 2000 total points
ID: 24167518
Right. I've now built, tested and finished the solution.
 
I have attached 2 screenshots. The first shows the rule that must be put in place to set the value in the getuserprofile data connection, followed by a second step which you must use to query the data connection after setting the value. This is necessary to get the value ready for the second box.
 
The second screenshot shows the second rule you must create. This sets the value of field 2, with the result of the query after passing the web service the value of field 1. The final window of the rule shows the filter you must apply by inputting Name="WorkEmail" which is the value you require. The Name part of this comes from the propertydata of the dadafields of the data connection.
 
:-)

IP1.jpg
IP2.jpg
0
 
LVL 25

Expert Comment

by:Robbie_Leggett
ID: 24168545
Did it work? I haven't heard back in a while.
 
:-)
0
 

Author Comment

by:agcps
ID: 24169217
Thanks a lot Robbie.
I was away from my seat and just finished it.
Thanks a ton, and appreciate your patience in explaining me.
0
 

Author Closing Comment

by:agcps
ID: 31570236
Very Clearly Explained
0
 
LVL 25

Expert Comment

by:Robbie_Leggett
ID: 24169316
I'm very glad it worked for you. Once you've got the hang of this, there are loads of other tricks to be found.
 
:-)
0
 

Author Comment

by:agcps
ID: 24173779
I went into an issue,

In my production there are users with preffered name with spaces like say
 preferredname = "firstname Lastname"

I think there spaces are throwing issues, Its unable to get.
Can you look into this once. Is it because of the space between firstname and lastname
0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft SharePoint Foundation 2010 and Microsoft SharePoint Server 2010 do not offer the option to configure the location of the SharePoint diagnostic trace log files during installation.  This can, however, be configured through Central Administr…
I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question