Event Object Actions

Contents

Event Object Actions

It is possible to perform actions such as disabling a field or displaying an error on a field by changing the properties of the event object and returning it. This section explains the available actions.

Number Fields

The following non-numeric values can be used when updating the value in the Number fields:

  • undefined null: The value in the Number field will become empty.
  • #INVALID!: The value in the Number field will not be changed.

Other non-numeric values are treated as invalid values in the Number field.

Record Create Events

Overwrite field values

If the event handler overwrites values in the fields of the record object and returns the event object, the fields of the record are updated with those values in the object.

Sample

When adding a new record, overwrite the field "text_0" with a specified string, overwrite the first line of the table "Table", and add values into "text_in_table" and "number_in_table" that are inside a table, as a new line.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
kintone.events.on('app.record.create.show', function(event) {
  var record = event.record;
  record.text_0.value = 'Overwrite with this value';
  record.Table.value[0].value.text_in_table.value = 'Overwrite first line of the table';

  // Add a row to the end of a subtable
  var newRow = {
    value: {
      text_in_table: {
        type: 'SINGLE_LINE_TEXT',
        value: 'New value for new row'
      },
      number_in_table: {
        type: 'NUMBER',
        value: '777'
      }
    }
  };
  record.Table.value.push(newRow);
  return event;
});

Note that when adding a new row to the table, all fields in the table must be specified, and the type of each field must also be specified.

Fields that cannot be Overwritten

Even if the below fields are overwritten in the handler and returned, they will not take effect on the record itself.

  • Calculated
  • The Field Mappings targets of the Lookup field
  • Attachment
Notes
  • If an empty string is specified for the Radio button field, the default value of the field will be inputted.
  • Values of the fields can be overwritten, even if the editing of the field has been disabled.
  • If you do not have permission to add values to a particular field, the field change written in the script will not take effect for that field.
  • If the handler does not return the event object, the fields will not be updated.
  • If there are several handlers, the returned values from the last handler will take effect.

Enable/Disable field edits

If the event handler inputs true/false in the disabled of a field of the record object and returns the event object, editing of those fields will become enabled/disabled.
Nothing will happen if this is applied to a field where you have no editing permissions.

Sample

When adding a new record, disable the editing of the "text_0" field when a value is selected in the drop down field "dropdown_0".

1
2
3
4
5
kintone.events.on('app.record.create.change.dropdown_0', function(event) {
  var record = event.record;
  record.text_0.disabled = true;
  return event;
});

Fields where editing cannot be enabled/disabled

Even if the below fields are returned with the disabled as true/false, they will not take effect on the record itself.

  • Record number
  • Created by
  • Created datetime
  • Updated by
  • Updated datetime
  • Status
  • Assignee
  • Calculated
  • Text Fields with the "Calculate automatically" option

Show field errors

If the event handler inputs an error message in the error of a field of the record object and returns the event object, an error message is displayed for the corresponding field.
In this case, the overwriting of field values and the enabling/disabling of field edits are canceled.
To remove error messages from fields, input null into the error of the field, and return the event object.

Sample

Show an error message for the fields "text_0" and "dropdown_0" when changing the value of a drop down field.

1
2
3
4
5
6
kintone.events.on('app.record.create.change.dropdown_0', function(event) {
  var record = event.record;
  record.text_0.error = 'This is an error';
  record.Table.value[0].value.text_in_table.error = 'This is another error';
  return event;
});

Fields that don't show error messages

Even if the below fields have error messages inputted by the handler and the object are returned, they will not take effect on the record itself.

  • Record number
  • Created by
  • Created datetime
  • Updated by
  • Updated datetime
  • Status
  • Assignee
  • Calculated

Show record errors

If the event handler inputs an error message in the error of the event object and returns the event object, an error message is displayed for the record.
In this case, the overwriting of field values and the enabling/disabling of field edits are canceled.

Sample

Show an error message for the record when changing a drop down field during the creation of a new record.

1
2
3
4
kintone.events.on('app.record.create.change.dropdown_0', function(event) {
  event.error = 'Your error message here!';
  return event;
});

Run Lookup fields

If true is entered into the lookup property, the Lookup field runs when the event is returned.

Sample

When adding a new record, the lookup value is set into the Lookup field, and the value is looked up. Any field mappings that were set in the Lookup field settings also take place.

1
2
3
4
5
6
kintone.events.on('app.record.create.show', function(event) {
  var record = event.record;
  record.lookup_0.value = '0001'; // The Lookup field value
  record.lookup_0.lookup = true;
  return event;
});

Clear copied Lookup field values

If CLEAR is entered into the lookup property of the Lookup field, the values copied from the source App due to the Lookup field settings are cleared when the event is returned.

Sample

When editing a record, the values copied from the source App due to the Lookup field settings are cleared.

1
2
3
4
5
kintone.events.on('app.record.edit.show', function(event) {
  var record = event.record;
  record.lookup_0.lookup = 'CLEAR';
  return event;
});

Get the object of the edited field or table row

An object containing data of an edited field and edited table row is retrieved.

Sample

Retrieve the object data of the field "dropdown_0" that exists inside a table, and the object data of the table row of the changed "dropdown_0" field, when the value of "dropdown_0" changes while creating a new record.

1
2
3
4
kintone.events.on('app.record.create.change.dropdown_0', function(event) {
  var row = event.changes.row;
  var field = event.changes.field;
});

Notes on non-numeric values in the Number field

  • #INVALID will be returned in event objects if non-numeric values are set in Number fields
  • Setting the value with an invalid value using Event Objects or JavaScript API will result in an error.
  • If the value is set to #INVALID!, the value will not change.
  • In the mobile view, if whitespaces are entered before or after a value, they will be sanitized.
  • When whitespaces are sanitized, as long as the final value does not change, events will not be triggered.

Record Details Event

Overwrite field values

If the event handler overwrites values in the fields of the record object and returns the event object, the fields of the record are updated with those values in the object.

Sample

When the process has progressed, overwrite the field "text_0" with a specified string, overwrite the first line of the table "Table", and add values into "text_in_table" and "number_in_table" that are inside a table, as a new line.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
kintone.events.on('app.record.detail.process.proceed', function(event) {
  var record = event.record;
  record.text_0.value = 'Overwrite with this value';
  record.Table.value[0].value.text_in_table.value = 'Overwrite first line of the table';

  // Add a row to the end of a subtable
  var newRow = {
    value: {
      text_in_table: {
        type: 'SINGLE_LINE_TEXT',
        value: 'New value for new row'
      },
      number_in_table: {
        type: 'NUMBER',
        value: '777'
      }
    }
  };
  record.Table.value.push(newRow);
  return event;
});

Note that when adding a new row to the table, all fields in the table must be specified, and the type of each field must also be specified.

Fields that cannot be Overwritten

Even if the below fields are overwritten in the handler and returned, they will not take effect on the record itself.

  • Calculated
  • The Field Mappings targets of the Lookup field
  • Attachment
Notes
  • If an empty string is specified for the radio button field, the default value of the field will be inputted.
  • Values of the fields can be overwritten, even if the editing of the field has been disabled.
  • If you do not have permission to add values to a particular field, the field change written in the script will not take effect for that field.
  • If the handler does not return the event object, the fields will not be updated.
  • If there are several handlers, the returned values from the last handler will take effect.

Record List Events

Overwrite field values

If the event handler overwrites values in the fields of the record object and returns the event object, the record is saved with those values in the object.

Sample

When saving an inline edit of a record, overwrite the field "text_0" and "text_in_table_0" with a specified string. "text_in_table_0" is a field that lies within a table with field code of "table_0".

1
2
3
4
5
6
kintone.events.on('app.record.index.edit.submit', function(event) {
  var record = event.record;
  record.text_0.value = 'Overwrite with this string';
  record.table_0.value[0].value.text_in_table_0.value = 'Overwrite first record in table';
  return event;
});
Fields that cannot be Overwritten

Even if the below fields are overwritten in the handler and returned, they will not take effect on the record itself

  • Calculated
  • The Field Mappings targets of the Lookup field
  • Attachment

Enable/Disable field edits

If the event handler inputs true/false in the disabled of a field of the record object and returns the event object, editing of those fields will become enabled/disabled.
Nothing will happen if this is applied to a field where you have no editing permissions.

Sample

Disable the editing of the "text_0" field when a value is selected in the drop down field "dropdown_0", during an inline edit of a record.

1
2
3
4
5
kintone.events.on('app.record.index.edit.change.dropdown_0', function(event) {
  var record = event.record;
  record.text_0.disabled = true;
  return event;
});
Fields where editing cannot be enabled/disabled

Even if the below fields are returned with the disabled as true/false, they will not take effect on the record itself.

  • Record number
  • Created by
  • Created datetime
  • Updated by
  • Updated datetime
  • Status
  • Assignee
  • Calculated
  • Text Fields with the "Calculate automatically" option

Show field errors

If the event handler inputs an error message in the error of a field of the record object and returns the event object, an error message is displayed for the corresponding field.
In this case, the Overwrite field values and the Enable/Disable field edits are canceled.
To remove error messages from fields, input null into the error of the field, and return the event object.

Sample

Show an error message for the fields "text_0" and "dropdown_0" when saving an inline edit for a record.

1
2
3
4
5
6
kintone.events.on('app.record.index.edit.submit', function(event) {
  var record = event.record;
  record.text_0.error = 'This is an error message';
  record.dropdown_0.error = 'This is also an error';
  return event;
});
Fields that don't show error messages

Even if the below fields have error messages inputted by the handler and the object is returned, they will not take effect on the record itself.

  • Record number
  • Created by
  • Created datetime
  • Updated by
  • Updated datetime
  • Status
  • Assignee
  • Calculated

Show record errors

If the event handler inputs an error message in the error of the event object and returns the event object, an error message is displayed for the record.
In this case, the Overwrite field values and the Enable/Disable field edits are canceled.

Sample

Show an error message for the record when changing a drop-down field during an inline edit of a record.

1
2
3
4
kintone.events.on('app.record.index.edit.change.dropdown_0', function(event) {
  event.error = 'This is an Error Message!';
  return event;
});

Get the object of the edited field

An object containing data of an edited field can be retrieved.

Sample

Retrieve the object data of the field dropdown_0 when the value of dropdown_0 changes during an inline edit of a record in the record list.

1
2
3
kintone.events.on('app.record.index.edit.change.dropdown_0', function(event) {
  var field = event.changes.field;
});

Action Limitations

These actions are only available on the Desktop, and not on the mobile.

Record Edit Events

Overwrite field values

If the event handler overwrites values in the fields of the record object and returns the event object, the fields of the record are updated with those values in the object.

Sample

After opening the record edit page, overwrite the field "text_0" with a specified string, overwrite the first line of the table "Table", and add values into "text_in_table" and "number_in_table" that are inside a table, as a new line.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
kintone.events.on('app.record.edit.show', function(event) {
  var record = event.record;
  record.text_0.value = 'Overwrite with this value';
  record.Table.value[0].value.text_in_table.value = 'Overwrite first line of the table';

  // Add a row to the end of a subtable
  var newRow = {
    value: {
      text_in_table: {
        type: 'SINGLE_LINE_TEXT',
        value: 'New value for new row'
      },
      number_in_table: {
        type: 'NUMBER',
        value: '777'
      }
    }
  };
  record.Table.value.push(newRow);
  return event;
});

Note that when adding a new row to the table, all fields in the table must be specified, and the type of each field must also be specified.
Also, if the first line of the table does not exist when you start editing, the code will not be able to find the first line, and will stop the script.

Fields that cannot be Overwritten

Even if the below fields are overwritten in the handler and returned, they will not take effect on the record itself.

  • Calculated
  • The Field Mappings targets of the Lookup field
  • Attachment
Notes
  • If an empty string is specified for the Radio button field, the default value of the field will be inputted.
  • Values of the fields can be overwritten, even if the editing of the field has been disabled.
  • If you do not have permission to add values to a particular field, the field change written in the script will not take effect for that field.
  • If the handler does not return the event object, the fields will not be updated.
  • If there are several handlers, the returned values from the last handler will take effect.

Enable/Disable field edits

If the event handler inputs true/false in the disabled of a field of the record object and returns the event object, editing of those fields will become enabled/disabled.
Nothing will happen if this is applied to a field where you have no editing permissions.

Sample

When editing a record, disable the editing of the "text_0" field when a value is selected in the drop down field "dropdown_0".

1
2
3
4
5
6
7
(function() {
  kintone.events.on('app.record.edit.change.dropdown_0', function(event) {
    var record = event.record;
    record.text_0.disabled = true;
    return event;
  });
})();

Fields where editing cannot be enabled/disabled

Even if the below fields are returned with the disabled as true/false, they will not take effect on the record itself.

  • Record number
  • Created by
  • Created datetime
  • Updated by
  • Updated datetime
  • Status
  • Assignee
  • Calculated
  • Text Fields with the "Calculate automatically" option

Show field errors

If the event handler inputs an error message in the error of a field of the record object and returns the event object, an error message is displayed for the corresponding field.
In this case, the overwriting of field values and the enabling/disabling of field edits are canceled.
To remove error messages from fields, input null into the error of the field, and return the event object.

Sample

Show an error message for the fields "text_0" and "dropdown_0" when changing the value of a drop down field.

1
2
3
4
5
6
kintone.events.on('app.record.edit.change.dropdown_0', function(event) {
  var record = event.record;
  record.text_0.error = 'This is an error';
  record.Table.value[0].value.text_in_table.error = 'This is another error';
  return event;
});

Fields that don't show error messages

Even if the below fields have error messages inputted by the handler and the object is returned, they will not take effect on the record itself.

  • Record number
  • Created by
  • Created datetime
  • Updated by
  • Updated datetime
  • Status
  • Assignee
  • Calculated

Show record errors

If the event handler inputs an error message in the error of the event object and returns the event object, an error message is displayed for the record.
In this case, the overwriting of field values and the enabling/disabling of field edits are canceled.

Sample

Show an error message for the record when changing a drop down field during an edit of a record.

1
2
3
4
kintone.events.on('app.record.edit.change.dropdown_0', function(event) {
  event.error = 'Your have selected the wrong option!';
  return event;
});

Run Lookup fields

If UPDATE or true is entered into the lookup property of the Lookup field, the Lookup field runs when the event is returned.

Sample

When editing a record, the lookup a value is set into the Lookup field, and the value is looked up. Any field mappings that were set in the Lookup field settings also take place.

1
2
3
4
5
6
kintone.events.on('app.record.edit.show', function(event) {
  var record = event.record;
  record.lookup_0.value = '0015'; // The Lookup field value
  record.lookup_0.lookup = true; // or record.'lookup_0'.'lookup' = 'UPDATE';
  return event;
});

Clear copied Lookup field values

If CLEAR is entered into the lookup property of the Lookup field, the values copied from the source App due to the Lookup field settings are cleared when the event is returned.

Sample

When editing a record, the values copied from the source App due to the Lookup field settings are cleared.

1
2
3
4
5
kintone.events.on('app.record.edit.show', function(event) {
  var record = event.record;
  record.lookup_0.lookup = 'CLEAR';
  return event;
});

Get the object of the edited field or table row

An object containing data of an edited field and edited table row is retrieved.

Sample

Retrieve the object data of the field dropdown_0 that exists inside a table, and the object data of the table row of the changed dropdown_0 field, when the value of dropdown_0 changes while editing a record.

1
2
3
4
kintone.events.on('app.record.edit.change.dropdown_0', function(event) {
  var row = event.changes.row;
  var field = event.changes.field;
});

Notes on non-numeric values in the Number field

  • #INVALID will be returned in event objects if non-numeric values are set in Number fields
  • Setting the value with invalid values using Event Objects or JavaScript API will result in errors.
  • If the value is set to #INVALID!, the value will not change.
  • In the mobile view, if whitespaces are entered before or after a value, they will be sanitized.
  • When whitespaces are sanitized, as long as the final value does not change, events will not be triggered.