Showing results for 
Search instead for 
Do you mean 
Community Home Request Access Read Blogs Share Your Ideas Search Community View My Settings
Reply
Highlighted
Tuned Listener
Posts: 26
Registered: ‎06-28-2010

Accessing Active Directory Information Tutorial

I wanted to share my experience of using active directory to get user information from within SalesLogix. I had a need to bring in all of the users who were in a group called sales along with their SalesLogix id numbers. We first started off by adding a new field into AD which you can just look up online or use one of the fields already in AD. I needed to bring in these users and have their binding element be their SLX ID in order to update my account table. Here is what I did:

 

string  group = "Sales",
                path = "your path goes here",  // Needs to be the fully qualified with where your LDAP server is such as                                                                                              LDAP://ldapserver.mycomany.com
                userName = "Admin",
                password = "Admin";
            
            //set up a new direcotry entry with the path, username and password
            DirectoryEntry de = new DirectoryEntry(path, userName, password);
    
            //set up a searcher
            DirectorySearcher ds = new DirectorySearcher(de);
                
            //create a filter (You can look up more filters online, I am filtering on the field department in AD
            ds.Filter = string.Format("(&(objectCategory=Person)(objectClass=user)(department={0}))",group);
            
            //set the scope
            ds.SearchScope = SearchScope.Subtree;
        
            //get the results
            SearchResultCollection results = ds.FindAll();

            //I used a sorted dictionary to keep the keys in alphabetical order which is useful for pick lists
            SortedDictionary<string, string> list = new SortedDictionary<string, string>();
            
            //iterate through the results
            foreach (SearchResult result in results)
            {
                //create a new entry
                DirectoryEntry entry = de;
                
                //set it to its new path
                entry.Path = result.Path;
                
                //get the display name
                string name = entry.Properties["displayName"].Value.ToString();
                
                //format the name like "Tyler, Steven"
                string first = name.Substring(0, name.IndexOf(" ")).Trim();
                string last = name.Substring(name.IndexOf(" ")).Trim();
                name = last + ", " + first;
                                
                //get the saleslogix userid
                string slx =  entry.Properties["employeeID"].Value.ToString();
                
                //the list will automaticall be sorted by last name aka the key
                list.Add(name,slx);
            }    
            
            //add the sorted dictionary to the fr and or item lists
            foreach (KeyValuePair<string, string> k in list)
            {
                   //add the items with the name as the display and the userID as the value.
                form.fieldRep.Items.Add(k.Key, k.Value);
                form.otherRep.Items.Add(k.Key, k.Value);
            }

 

I hope this is clear and will be able to help somebody out. If anyone has any questions feel free to ask.

 

Good Coding,

 

Matthew