scripts:catalogs

Catalogs

You can get values from catalogs and paste them into forms using the getCatalog method. For example, you can calculate table values or filter a catalog with values taken from another one.

Suppose a user selected a state in the State field and we only want cities from the selected state to be available in the City field.

In our example, the State field corresponds with the States catalog while the City field corresponds to the Cities catalog. There is also a States and cities catalog that lists cities by region.

To filter the list of cities by selected state, add the following script to the form:

let catalogItems = null;

form.getCatalog("
USA states and citiesThe name of a catalog that binds values from two other catalogs
").then(items => { catalogItems = items; }); form.onChange(["
StateThe name of the form field that defines values available for the City field
"]).setFilter("
CityThe form field where values change depending on the value selected in the State field.
", state => { if (!catalogItems || !state.changes[0] || !state.changes[0].columns) return null; const region = state.changes[0].columns["
StateThe title of the column that defines values available in the City field
"]; const filtered = catalogItems .filter(item => item.columns["
StateThe title of the column that defines values available in the City field
"] === region) .map(item => item.columns["
CityThe name of the column where potential City fields come from
"]); return filtered.length > 0 ? { values: filtered } : null });

Was this article helpful?

Yes, thanks! No, I have a question