Link to home
Start Free TrialLog in
Avatar of agcps
agcps

asked on

get the email ID from AD

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!
Avatar of agcps
agcps

ASKER

Adding to my Question, I would like to inform that its a browser enabled form, that is published on a sharepoint site
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?
Avatar of Robbie_Leggett
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.

:-)
Avatar of agcps

ASKER

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.
Then create a filter specifying
textbox value = emailid
where
PreferredName = dropdown box
 
:-)
Avatar of agcps

ASKER

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
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.
 
:-)
Avatar of agcps

ASKER

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
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?
 
:-)
Avatar of agcps

ASKER

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

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.
 
:-)
Avatar of agcps

ASKER

Let me know the steps to do the above.

Thanks a lot in advance
Avatar of agcps

ASKER

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.
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 = .)
 
:-)
Avatar of agcps

ASKER


I tried but didn't get the way to do this.
Can you give me the steps
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.
 
:-)
Avatar of agcps

ASKER

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
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.
 
:-)
Avatar of agcps

ASKER


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

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

 
:-)
Avatar of agcps

ASKER

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
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
 
:-)
Avatar of agcps

ASKER

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
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
ASKER CERTIFIED SOLUTION
Avatar of Robbie_Leggett
Robbie_Leggett
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Did it work? I haven't heard back in a while.
 
:-)
Avatar of agcps

ASKER

Thanks a lot Robbie.
I was away from my seat and just finished it.
Thanks a ton, and appreciate your patience in explaining me.
Avatar of agcps

ASKER

Very Clearly Explained
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.
 
:-)
Avatar of agcps

ASKER

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