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 => { const [region] = state.changes; if (!catalogItems || !region || !region.columns) return null; const regionCol = 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
"] === regionCol) .map(item => item.columns["
CityThe name of the column where potential City fields come from
"]); return filtered.length > 0 ? { values: filtered } : null });

Pay attention: you can filter catalogs not only by their name, but also by ID number. In this case, the code in the script will look like this:

let catalogItems = null;

form.getCatalog(
123The ID of a catalog that binds values from two other catalogs
).then(items => { catalogItems = items; });

Was this article helpful?

Yes, thanks! No, I have a question