# Creating an Option List Based on an LDAP Query

## About this task

In Morpheus version 4.2.1 and higher, Option Lists can be populated from LDAP queries. This gives users the ability to search Active Directory, capture objects, and present them as custom options where needed.

It’s recommended that you connect LDAP-type Option Lists to Typeahead-type Inputs as the list of returned selections can be very large. This also allows you to select multiple options from the list, presuming you’ve allowed for that when creating the Input.

Populating LDAP-type Option Lists requires knowledge of LDAP query syntax. This guide provides one example and there are many publicly-available resources for help writing additional queries.

## Procedure

1. Create a new Option List (Library > Options > Option Lists > ADD)
2. Enter a name for the new LDAP Option List
3. Change the Type value to LDAP and the relevant fields will appear as shown in the screenshot:
4. Enter the LDAP URL in the following format (an example is also shown as a placeholder in the UI form field): 

   ```
   ```
   ldap[s]://<hostname>:<port>/<base_dn>
   ```
   ```
5. Enter the fully qualified username with @ suffix syntax, such as: user@ad.mycompany.com
6. Enter the account password
7. Enter your LDAP query. You can even inject variables into your query structure to query based on the value the user has entered into the typeahead field as shown in the example below: 

   ```
   ```
   (&(objectClass=user)(cn=<%=phrase%>*))
   ```
   ```
8. Finally, enter a translation script which will convert the returned LDAP object into a list of name:value pairs you can work with in Morpheus. The example script below shows the user DisplayName and sets the value to the SAMAccountName: 

   ```
   ```
   for(var x=0;x < data.length ; x++) {  
     var row = data[x];  
     var a = {};  
     if(row.displayName != null) {  
       a['name'] = row.displayName;  
     } else {  
       a['name'] = row.sAMAccountName;  
     }  
     a['value'] = row.sAMAccountName;  
     results.push(a);  
   }
   ```
   ```
9. Click SAVE CHANGES 

   ![../../_images/ldap_option_list.png](https://support.hpe.com/hpesc/public/api/document/sd00007621en_us/GUID-F3A370B1-BB00-4177-8AF4-D6E5A2975918-high.png)
