Record Edit Event

 

Record Edit Events

Onload Event (desktop)app.record.edit.show

An event triggered after the Record Edit page is displayed on the desktop.

Function

app.record.edit.show

Triggered Timing

  • After the Record Edit page is displayed, i.e. when there is an mode=edit in the URL of the page.
  • After the Record Edit page is displayed through a notification.

Properties of the Event Object

PROPERTY TYPE DESCRIPTION
appId Number The App ID.
record Object The record object.
recordId Number The record ID

Possible Actions

Onload Event (mobile)mobile.app.record.edit.show

An event triggered after the Record Edit page is displayed on the mobile.

Function

mobile.app.record.edit.show

Triggered Timing

  • After the Record Edit page is displayed on the mobile.

Properties of the Event Object

PROPERTY TYPE DESCRIPTION
appId Number The App ID.
record Object The record object.
recordId Number The record ID

Possible Actions

Save Submit Eventapp.record.edit.submit

An event triggered when the save button is clicked on the Record Edit page.

Function

Desktop

app.record.edit.submit

Mobile

mobile.app.record.edit.submit

Properties of the Event Object

PROPERTY TYPE DESCRIPTION
appId Number The App ID.
record Object A record object that holds data inputted by the user.
recordId Number The record ID.

Possible Actions

Running actions after waiting for asynchronous operations to finish

By returning the kintone.Promise object, you can run actions after waiting for asynchronous operations to finish. Refer to the sample code for the "Save Submit Event" event on the Record Create page.

Save Submit Success Eventapp.record.edit.submit.success

An event triggered after the record has been successfully saved after clicking the save button on the record edit page on the Desktop.

Function

app.record.edit.submit.success

Properties of the Event Object

PROPERTY TYPE DESCRIPTION
appId Number The App ID.
recordId Number The Record ID.
record Object A record object that holds data of the saved record.

Possible Actions

Sample

// Display the updated date time after saving.
kintone.events.on("app.record.edit.submit.success", function(ev) {
		var record = ev.record;
		alert("The updated date time is " + record["Updated_datetime"]["value"] + ".");
});

Notes

  • This event is only available on the Desktop.
  • This event cannot be used with an app embedded on a space.
  • The event will not trigger if the record does not successfully save.

Field Change Eventapp.record.edit.change.<>

An event triggered when a specified field value changes while a record is being edited.

Function

Desktop

app.record.edit.change.<fieldcode>

Mobile

mobile.app.record.edit.change.<fieldcode>

Fields that can be Specified

The same as the "Field Change Event" event for the Record Create event.

Properties of the Event Object

PROPERTY TYPE DESCRIPTION
appId Number The App ID.
record Object A record object that holds form data inputted by the user at the point of the event.
recordId Number The Record ID
changes Object An object including data of changed fields and rows.
changes.field Object An object of the changed field.
changes.row Object An object of the changed row.
  • If a row is added to a table: change.row will reference the new row object.
  • If a row is deleted from a table: change.row will be null.
  • If a field outside of a table is changed: change.row will be null.

Possible Actions

Event Limitations

The below events are only available on the Desktop, and not on the mobile:

 

Available Actions

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.

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 single-choice 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".

(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.

  • Calculated
  • The Field Mappings targets of the Lookup field

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.

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

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.

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 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.

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;
  return event;
});

Show/Hide fieldskintone.app.record.setFieldShown()

Changes fields to be hidden or shown. For the second parameter, "false" makes a field hidden, and "true" makes a field shown.

Function

Desktop

kintone.app.record.setFieldShown("fieldcode","true/false")

Mobile

kintone.mobile.app.record.setFieldShown("fieldcode","true/false")

Sample

Hiding a field with a field code of "text0" when editing a record.

kintone.events.on('app.record.edit.show', function(event){
    kintone.app.record.setFieldShown('text_0', false);
});

The below fields cannot be hidden:

  • Label
  • Border
  • Blank space
  • Fields inside tables

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.

kintone.events.on('app.record.edit.change.dropdown_0', function(event) {
    var row = event.changes.row;
    var field = event.changes.field;
});
Was this article helpful?
0 out of 0 found this helpful
Comments
Please sign in to leave a comment.