Solved

get the email ID from AD

Posted on 2009-04-14
31
825 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
  • 15
  • 15
31 Comments
 

Author Comment

by:agcps
Comment Utility
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
Comment Utility
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
Comment Utility
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
 

Author Comment

by:agcps
Comment Utility
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
Comment Utility
Then create a filter specifying
textbox value = emailid
where
PreferredName = dropdown box
 
:-)
0
 

Author Comment

by:agcps
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Let me know the steps to do the above.

Thanks a lot in advance
0
 
LVL 25

Expert Comment

by:Robbie_Leggett
Comment Utility
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
Comment Utility
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
Comment Utility
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Author Comment

by:agcps
Comment Utility

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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility

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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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 500 total points
Comment Utility
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
Comment Utility
Did it work? I haven't heard back in a while.
 
:-)
0
 

Author Comment

by:agcps
Comment Utility
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
Comment Utility
Very Clearly Explained
0
 
LVL 25

Expert Comment

by:Robbie_Leggett
Comment Utility
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
Comment Utility
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Work Over Net is a new and very powerful collaboration product. With its new easy interface it is becoming very competitive to other similar products like webex and office interactive. WON 2010 have the standard business tools needed for multi-offic…
When installing SharePoint 2010 RTM I came across a strange error, I was getting timeouts during the installation. I searched the web and found the best solution to be found here (http://social.msdn.microsoft.com/Forums/en-US/sharepoint2010genera…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

743 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now