Definition
To define one you include thedynamic property on the inputFields object. The value for the property is a dot-separated string concatenation.
- The key of the trigger you want to use to power the dropdown. required
- The value to be made available in bundle.inputData. required
- The human friendly value to be shown on the left of the dropdown in bold. optional
Use a resource
In the first code example the dynamic dropdown is powered by a trigger. You can also use a resource to power a dynamic dropdown. To do this combine the resource key and the resource method using camel case.index.js
Function-based dynamic dropdowns (perform)
Instead of powering a dropdown from a trigger or resource list viadynamic, you can power it with a function using choices: { perform: getChoices }. The function is called when the UI needs options and can use bundle.inputData (for example from other dropdowns) and support pagination.
When to use: Use this when you want a dedicated function to fetch options (e.g. from an API that isn’t already a trigger or resource list), when you need pagination for many options, or when you want explicit dependencies declared on the field.
Defining the choices function
Addchoices with a perform function on the input field. The function receives (z, bundle) and can read bundle.inputData for values from other fields (e.g. a parent dropdown).
The function must return an object with a results key containing an array of choice items, and an optional paging_token for pagination:
results can be:
- A string — used as both the value and the label (the label is automatically humanized, e.g.
"my_option"becomes"My Option") - An object with
id(orkeyorvalue) andlabel
Pagination
If the API supports paging, setpaging_token to a string value (typically a URL or cursor) that the platform will pass back on the next call via bundle.meta.paging_token. Return paging_token: null when there are no more pages.
On the first call, bundle.meta.paging_token will be undefined, so you can use it to determine whether to fetch the first page or a subsequent one.
dependsOn
UsedependsOn to declare which input fields this dropdown depends on (e.g. a parent spreadsheet). The platform uses this for ordering and to ensure those values are in bundle.inputData when calling your choices.perform function. List the keys of the fields the user must fill first.
If dependsOn is not explicitly set, the platform will attempt to derive dependencies automatically from the field’s dynamic property (if present).
choices.perform and dependsOn on the same field as in the first example in this section.
Hide the trigger
In some cases you will need to power a dynamic dropdown but do not want to make the Trigger available to the end user. Here it is best practice to create the trigger and sethidden: true on it’s display object.
Dependencies between dropdowns
You can have multiple dynamic dropdowns in a single trigger or action. In some cases, a dynamic dropdown depends on the value chosen in another dynamic dropdown when making its API call. The Google Sheets integration displays an example of this pattern. The example below illustrates a ‘New Worksheet’ trigger that populates a dynamic dropdown input field to select a worksheet:New Records trigger with Spreadsheet and Worksheet dynamic dropdown input fields, which have keys spreadsheet_id and worksheet_id respectively. The selected spreadsheet value is available via bundle.inputData.spreadsheet_id to be used by the Worksheet trigger.
Note: Be mindful that a dynamic dropdown can depend on the value chosen in another dynamic dropdown. Two types of dependencies can exist between fields: Requirement dependency: Affects how dependent fields are enabled or disabled within the UIValue dependency: Affects how dynamic dropdown field options are retrieved
- Setting
required: falsemakes a field optional and always enabled in the UI.- Having no required value set makes a field optional and disabled until the dependencies are selected.
So, if you have an optional dynamic dropdown that depends on another dropdown input field, that field should not have
- Setting a required value or not does not affect how the options of a dynamic field are retrieved.
required: falseset. Input fields are optional by default, but settingrequired: falseon an optional dynamic dropdown field that depends on another removes the requirement dependency relationship. In the example above, theworksheet_idinput field will be disabled until thespreadsheet_idinput field has a value in Zapier’s products such as the Zap editor. Notice that settingaltersDynamicFields: truesignifies other input fields need to be recomputed whenever the value of that field changes.
Detect when a trigger is used for a dynamic dropdown
If you want your trigger to perform specific scripting for a dynamic dropdown you will need to make use ofbundle.meta.isFillingDynamicDropdown. This can be useful if need to make use of pagination in the dynamic dropdown to load more options.
Link a search action
This feature makes it easier for users to handle the following scenario in a workflow that has multiple steps:- The value for the input field depends on an output field from an earlier step.
- The value of that output field cannot be used directly.
- They need an additional search step that takes the output they cannot use directly, and translate it into something they can.
How it works for the user
In the Zap editor for example, dynamic dropdowns that use this feature will display a button next to the dynamic dropdown. When the user clicks the button, the right search step is automatically prepended, and correct output field mapped into the dynamic dropdown.
How to configure it
In the definition of the input field, configuresearch with a value of <searchActionKey>.<outputFieldKey>.
- Replace
<searchActionKey>with thekeyof the search action that should prepeded to the user’s workflow. - Replace
<outputFieldKey>with thekeyof the output field from that search action that should be mapped as value for the input field.