Get Field Names
Maintained on
By using the event object, which is the argument of the kintone.events.on callback function, you can retrieve the record information displayed in the list or detail view.
However, you can only get the field code, field type, and value from this, and the field name is not included.
This time, we will introduce a method to retrieve the field names set in a specific list.
Sample Code
As an example, here is the code to retrieve the field names for each field in the record detail view. Note that in the record list view, the event.record object does not exist, and instead, it becomes event.records.
kintone.events.on(['app.record.detail.show'], async (event) => {
/** Record information */
const record = event.record;
/** Form settings information */
const { properties } = await kintone.api(
kintone.api.url('/k/v1/app/form/fields.json', true),
'GET',
{ app: kintone.app.getId() }
);
/** Field code and corresponding field name */
const pairs = Object.keys(record).map((fieldCode) => {
return [fieldCode, properties[fieldCode]?.label];
});
console.log(pairs);
return event;
});
Execution Result
Here is the execution result using the sample app.
0: (2) ['Record number', 'Record number']
1: (2) ['Updater', 'Updater']
2: (2) ['Creator', 'Creator']
3: (2) ['Update time', 'Update time']
4: (2) ['Creation time', 'Creation time']
5: (2) ['name', 'Name']
6: (2) ['kana', 'Name (Kana)']
7: (2) ['gender', 'Gender']
8: (2) ['phoneNumber', 'Phone number']
9: (2) ['birthday', 'Birthday']
10: (2) ['$revision', undefined]
11: (2) ['$id', undefined]
#JavaScript
#kintone