---
schema_version: "1"
id: 4024b27cd0302c86a49f8fcbb26f3fc099c6c7f8339773fa48d89a799ff218e6
title: Populate the Options Programmatically (Managed Package)
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/xcloud/264-0-0/os_configure_options_programamatically_vlocity.md
canonical_url: https://help.salesforce.com/s/articleView?id=xcloud.os_configure_options_programamatically_vlocity.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: a8283fa4183ef2f4dd6d7a454116c0c00d16616680dbaa769c2a386968d0b6c1
description: For the managed package runtime, use Apex to populate options for a Select element.
products:
  - Omnistudio
release: "264"
---
# Populate the Options Programmatically (Managed Package)

For the managed package runtime, use Apex to populate options for a Select element.

![Managed Package app icon](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-xcloud-omnistudio_for_managed_packages-264-0-0-production-enus/aa2554ec-624a-4ee6-8da4-6435670e6e62/resources-global/_corporate/images/managedpackageicon.png) This information is for Omnistudio for Managed Packages. For Omnistudio on standard runtime, see [Omnistudio Help](https://help.salesforce.com/s/articleView?id=xcloud.os_omnistudio_standard.htm&language=en_US).

1. Create a class and method that returns a map of options translated according to the language code in effect when the method is called. See the sample code below.
2. Add a Select element to your Omniscript, configured as follows:
    
    - **Option Source**: Custom
    - **Source**: The class and method that return options
    
    ![Note](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-xcloud-omnistudio_for_managed_packages-264-0-0-production-enus/aa2554ec-624a-4ee6-8da4-6435670e6e62/images/icon_note.png)
    
    Note For dependent Select elements that are populated programmatically (custom), configure a controlling field by specifying the name of an Omniscript element that contains the value that determines the options in the dependent Select element. (For example, a list of cities might depend on a state specified in another element.) For the dependent element, specify its CONTROLLING FIELD settings as follows:
    
    - **Option Source**: Custom
    - **Source**: Omit
    - **Element**: The Omniscript element containing the value that determines how this dependent element is populated.
    
    The Apex method that returns the values that populate the Select element must contain logic that uses the value of the controlling element and the language code to determine what values to return to populate the dependent element.

![Example](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-xcloud-omnistudio_for_managed_packages-264-0-0-production-enus/aa2554ec-624a-4ee6-8da4-6435670e6e62/images/icon_example.png)

Example

```java
global class PicklistPopulation implements VlocityOpenInterface { public Boolean invokeMethod(String methodName, Map<String, Object> input, Map<String, Object> outMap, Map<String, Object> options) { try { if (methodName.equals('PopulatePicklist')) { PopulatePicklist(input, outMap, options); } else if (methodName.equals('PopulateDependentPicklist')) { PopulateDependentPicklist(input, outMap, options); } } catch (Exception e) { System.debug(LoggingLevel.ERROR, 'Exception: ' + e.getMessage() + ' ' + e.getStackTraceString()); } return true; } // Get All Contacts Associated with the ContextId Account where the Omniscript is Launched public void PopulatePicklist(Map<String, Object> input, Map<String, Object> outMap, Map<String, Object> options) { List<Map<String,String>> plOptions = new List<Map<String, String>>(); String lang = (String)input.get('LanguageCode'); for(Integer i=0; i<2; i++) { Map<String, String> tempMap = new Map<String, String>(); tempMap.put('name', 'test'+ String.valueOf(i)); // Language Independent tempMap.put('value', 'testV'+ String.valueOf(i)); // Displayed in Picklist UI if(lang == 'zh_CN') tempMap.put('value', 'testV' + String.valueOf(i) + ' 中文'); plOptions.add(tempMap); } outMap.put('options',plOptions); } // Populate a Dependent Picklist based on the Contacts ReportsToId Field Selected in the Other Field this field depends on public void PopulateDependentPicklist(Map<String, Object> input, Map<String, Object> outMap, Map<String, Object> options) { // Map of List where the Key is the Potential Values in the Other Picklist Map<String, List<Map<String, String>>> dependency = new Map<String, List<Map<String, String>>>(); String lang = (String)input.get('LanguageCode'); String elementName = (String)input.get('controllingElement'); // itself Logger.debug('hello1 ' + lang); Logger.debug('hello2 ' + elementName); List<String> controlValList = new List<String>(); controlValList.add('Licensing & Permitting'); controlValList.add('Contract'); for(Integer i=0; i<2; i++) { List<Map<String, String>> optionList = new List<Map<String, String>>(); for(Integer j=0; j<2; j++) { Map<String, String> tempMap = new Map<String, String>(); tempMap.put('name', controlValList[i] + 'Child' + String.valueOf(j)); // Language Independent tempMap.put('value', controlValList[i] + 'ChildV' + String.valueOf(j)); // Displayed in Picklist UI if(lang == 'zh_CN') tempMap.put('value', controlValList[i] + 'ChildV' + String.valueOf(j) + ' 中文' ); optionList.add(tempMap); } dependency.put(controlValList[i], optionList); } outMap.put('dependency',dependency); } }
```