It is common knowledge that Dynamics CRM is based on Windows authentication. This means that for the users to be able to access Dynamics CRM, they should exist in Active Directory (AD) before they can be added as Users in Dynamics CRM.
At the time of adding a System User in CRM, it asks you to enter the windows logon id, with that entered, it automatically auto populates the other information for the user like user name, email address etc. This information is picked from the AD User account that was created.
If suppose, you would like some additional custom information to be brought over from AD when the user is created, you will need to read the AD account and have the plugin set the information in your custom attribute.
You will need to access the LDAP functions made available to read the AD user account. Read the information required and update it in CRM attributes.
Sample code:
//Get AD root path
objRootEntry = new DirectoryEntry(strRootPath);
//Init object for ADsearcher
objADSearcher = new DirectorySearcher(objRootEntry);
// search for a given user name
objADSearcher.Filter = String.Format(@"(&(objectClass=user)(anr={0}))", strLogin);
// Find
objResult = objADSearcher.FindOne();
//get the emaiid from the AD user properties //You can use your custom attribute property to read its value
if (objResult.GetDirectoryEntry().Properties["mail"] != null)
{
strUserEmail = objResult.GetDirectoryEntry().Properties["mail"].Value.ToString();
}
References:
http://msdn.microsoft.com/en-us/library/aa367033(VS.85).aspx
No comments:
Post a Comment