Extract Specific Fields from Form Settings

Maintained on

In kintone, you can use the API to retrieve field information for a specified app.

However, the API request parameters only allow you to set the app ID and language, so all fields of the specified app are retrieved.

This includes standard fields such as record ID, creation date, and update date, as well as unused category fields.

This article introduces a method to extract only specified fields from the form information retrieved using the API.

Definition of a Generic Function

First, define a function as follows.

export const filterFieldProperties = (properties, callback) => {
  const filtered = Object.entries(properties).filter(([_, value]) => callback(value));

  const reduced = filtered.reduce((acc, [key, value]) => ({ ...acc, [key]: value }), {});

  return reduced;
};

The function takes all fields retrieved from the API and a filtering condition.

It returns only the fields that match the specified condition.

The reason for filtering with Object.entries and then reducing is to return the result in the same format as the input.

Usage Example

/* List of fields filtered to include only single-line text fields */
const filtered = filterFieldProperties(
  properties,
  (property) => property.type === 'SINGLE_LINE_TEXT'
);

Exclude Specified Field Types

Using the aforementioned function, here is a function that takes an array of field types and removes them from all fields.

export const omitFieldProperties = (properties, omittingTypes) => {
  return filterFieldProperties(properties, (property) => !omittingTypes.includes(property.type));
};

Usage Example

/* List of fields with record number and creator removed */
const omitted = omitFieldProperties(properties, ['RECORD_NUMBER', 'CREATOR']);
#JavaScript #kintone