Get Current User - query Active Directory for email address
I have a workflow that automatically sends an email using a default email address. I would like to be able to use the current user's email address to send the email. I can use GetCurrentUser to return the user name but I would like to use this value to query active directory. Any suggestions?
Thanks,
Aron
-
Use PrincipalContext from the System.DirectoryServices.AccountManagement namespace.
I found this exsample and modified it to get the rigth office name and full name on map prints.
http://www.codeproject.com/Articles/38344/Using-System-DirectoryServices-AccountManagement
0 -
Hi Sebastian
Is there any chance you could post your code for implementing the search in active directory after getting the current user ID? We would like to do something similar but my coding skills aren’t at the level to understand and apply the code in the link you posted.
Thanks
Shaun
0 -
I Have copyed the workflow to my public dropbox.
You can find it here
https://dl.dropboxusercontent.com/u/41049387/GeoCortex/GetAdName.xaml
Here you can see what you can get from the userprincipal class
/customer/servlet/servlet.FileDownload?file=00P6000000e88ZoEAI
0 -
thanks sebastian, works perfectly
0 -
Hi,
I'm trying to get the emailaddress of the current user using System.DirectoryServices.AccountManagement.UserPrincipal.Current.EmailAddress and it works in the Workflow simulator, but when running it on the server I get this error:
<< Unhandled exception: 'Unable to cast object of type 'System.DirectoryServices.AccountManagement.GroupPrincipal' to type 'System.DirectoryServices.AccountManagement.UserPrincipal'.' in activity '1.654: Assign'. >>
I then tried it in 2 steps:
PrincipalContext ctx = new PrincipalContext(ContextType.Domain);
UserPrincipal user = UserPrincipal.FindByIdentity(ctx, "UserName");
But get another error:
<< 'Type 'System.DirectoryServices.AccountManagement.PrincipalContext' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute. If the type is a collection, consider marking it with the CollectionDataContractAttribute. ...>>
I don't see how I can do this in the workflow designer.
?Any help is welcome.
Patricia Bongaerts
Port of Antwerp0 -
Hi Patricia,
You are using AD to secure the app right? If so, I have a colleague who did this the other day, I'll forward him this thread and see if he can help out.
-Kevin0 -
Hi Patricia,
I have recently worked on a similar AD email authentication in the workflow designer.
Here is what I did to retrieve the AD email claim:- Use a GetCurrentUser activity to obtain their list of claims.
- Use an Assign activity to find the AD email claim as follows:
iEnumUserClaims.Where(Function(x) x.Type = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress").FirstOrDefault() - Use an If activity to confirm that the user has an AD email claim.
_img_ alt="User-added image" src="https://latitudegeo--c.na53.content.force.com/servlet/rtaImage?eid=907f2000000kA8l&feoid=Body&refid=0EMf2000000fyR9"_/_img_
Let me know if you have any questions.
-Matt0 -
Hi Matt,
This works perfectly! Thank you so much.
Patricia0 -
@Mattew it may couple years old post. I was scratching my head to get AD email of current user. your post solved the problem. thanks. 0
Please sign in to leave a comment.
Comments
9 comments