Record Create Event

 

List of Events for the Record Create

On the Record Create Page (Desktop)app.record.create.show

An event triggered after the record create page is displayed on the desktop.

Function

app.record.create.show

Triggered Timing

  • After the record create page is displayed, i.e. when there is an /edit in the URL of the page. This can be displayed in the following ways:
    • by clicking the "New record" icon (the plus icon) on either the record list page or record details page.
    • by clicking the "Duplicate" icon (the paper icon) on the record details page.

Properties of the Event Object

PROPERTY TYPE DESCRIPTION
appId Number The App ID.
reuse Boolean true if the page is a duplicate of a record (i.e. the "Duplicate" icon was clicked on a record to display the page), false if the page is a regular record create page.
record Object The record object, containing the default value of the fields.

Possible Actions

On the Record Create Page (Smartphone)mobile.app.record.create.show

An event triggered after the record create page is displayed on the smartphone app.

Function

mobile.app.record.create.show

Triggered Timing

  • After the record create page is displayed on the mobile. This can be displayed in the following ways:
    • by clicking the "New" icon (the plus icon) on the record list page.
    • by clicking the "Duplicate" icon (the paper icon) on the record details page.

Properties of the Event Object

PROPERTY TYPE DESCRIPTION
appId Number The App ID.
reuse Boolean true if the page is a duplicate of a record (i.e. the "Duplicate" icon was clicked on a record to display the page), false if the page is a regular record create page.
record Object The record object, containing the default value of the fields.

Possible Actions

When Clicking the Save Buttonapp.record.create.submit

An event triggered when the save button is clicked on the record create page.

Function

Desktop

app.record.create.submit

Mobile

mobile.app.record.create.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.

Possible Actions

Running actions after waiting for asynchronous operations to finish

By returning a kintone.Promise object, you can run actions after waiting for asynchronous operations to finish. If an error occurs and the Thenable object is rejected, the event will be cancelled.

Sample request using the kintone.Promise object returned by the kintone.api

kintone.events.on('app.record.create.submit', function(event) {
	var record = event.record;
	var companyName = record['company_name'].value || '';
    var masterAppId = 21; //App ID of a different app
    var query = 'company_name="' + companyName + '"';
    var params = {app: masterAppId, query: query};

    return kintone.api('/k/v1/records', 'GET', params).then(function(resp) {
    //Check that the company name exists in the master app
    if (!resp.records.length) {//Set an error message on the field
    		record['company_name'].error = 'Company name does not exist.';
    	}
    	else {//The record will save when the alert window closes
    		alert("Found company");
    	}
    	return event;
    },	function (resp){//Dealing with errors received by the system
    		var errmsg = 'There was an error when retrieving the data.';
    		if (resp.message){
    		errmsg += '\n' + resp.message;
    		}
    		alert(errmsg);
       	}
    );
});

Sample request using the kintone.Promise Constructor

kintone.events.on('app.record.create.submit', function (event) {
    var record = event.record;
    var companyName = record['company_name'].value;
    var masterAppId = 21; //App ID of a different app
    var query = 'company_name="' + companyName + '"';
    return new kintone.Promise(function(resolve, reject) {
        var params = {app: masterAppId, query: query};
        kintone.api('/k/v1/records', 'GET', params, function(resp) {
            resolve(resp);
        });
    }).then(function(resp) {
        if (!resp.records.length) {
            record['company_name'].error = 'Company name does not exist.';
        }
        return event;
    });
});

When a Field Value Changesapp.record.create.change.<>

An event triggered when a specified field value changes when creating a new record.

Function

Desktop

app.record.create.change.<fieldcode>

Mobile

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

Fields that can be Specified

  • Single choice
  • Drop-down
  • Check box
  • Multi-choice
  • User selection
  • Date
  • Time
  • Date and time
  • Single-line text
  • Number
  • Table

Make sure to specify the field codes of these fields. Nothing will happen if the field code does not exist, or a field that is not in the above list is specified.

*The timing of the event for the Single-line text and Number field are as below:

  • when the focus leaves the field.
  • when the Lookup field mappings have been run.
  • after calculations have been applied to a Single-line text field that has the "Calculate automatically" option turned on.

*The timing of the event for the Table is as below:

  • when a new row is added to the table
  • when a row is deleted from the table

Properties of the Event Object

PROPERTY TYPE DESCRIPTION
appId Number The App ID.
record Object A record object including data inputted by the user at the time of the event..
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.

Notes

The change in value of the trigger field cannot be cancelled.

Possible Actions

Submit Success Eventapp.record.create.submit.success

An event triggered after the record has been successfully saved after clicking the save button on the record create page or the record duplicate page on the desktop.

Function

app.record.create.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 record ID published after saving.
kintone.events.on("app.record.create.submit.success", function(ev) {
	    var record = ev.record;
	    alert("The record ID is " + record["$id"]["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.

Record Create Event Limitations

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

 

Possible Actions after Events are Triggered

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.

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 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 adding a new record, disable the editing of the "text_0" field when a value is selected in the drop down field "dropdown_0".

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.

  • Calculated
  • The Field Mappings targets of the Lookup field

Show a Field Error

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.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 is returned, they will not take effect on the record itself.

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

Show a Record Error

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 a creation of a new record.

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

Run the Lookup field

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 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.create.show', function(event) {
  var record = event.record;
  record['lookup_0']['value'] = '0001'; // 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 adding a new record.

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

The below fields cannot be hidden:

  • Label
  • Border
  • Blank space
  • Fields inside tables

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

kintone.events.on('app.record.create.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.