In This Topic
Record saving or editing procedures on krewSheet can be obtained through Event.
Additionally, krewSheet provides the event API equivalent to that of Kintone. This section describes details of the event API supported by krewSheet
*Please use the Kintone standard API for manipulation of values other than event argument in krewSheet.
Event
Executable Operations when an Event has Occurred
- The event API of krewSheet can only be used on PC version.
- Please note that krewSheet's operation becomes possible only with the parameters of each event. Thus, krewSheet can't be operated from API at any desired timing.
This is an event that fires when record view screen (using krewSheet) is displayed.
If a Kintone.Promise object is returned, event processing begins upon the completion of asynchronous processing.
Event Type
app.record.index.show
Timing of Event Firing
- At the time of displaying record view screen
- At the time of sending page on record view screen
- When sorting is done in record view screen
- When a filtering condition for the record view screen is applied
Event Object Property
Property Name |
Type |
Description |
appId |
Number |
App ID |
viewType |
String |
Custom (krewSheet supports [Customize] format view only) |
viewId |
Number |
View ID |
viewName |
String |
View Name |
records |
Array |
Array of record object |
offset |
Number |
Number of offsets of the view |
size |
Number |
Number of records of the view |
date |
String |
null |
type |
String |
Event type |
Control Depending on Field value
This function isn't available.
Event - Before Executing the Save Operation
This event fires when records are saved. It fires only once when multiple records are saved simultaneously.
Multiple records can be obtained only from the data changed by the Records property of the event object.
If a Kintone.Promise object is returned, event processing starts upon the completion of asynchronous processing.
Event Type
app.record.index.edit.submit
Firing Time
- When the Save button on the command bar is clicked
- When "Save selected row" of the context menu is selected
- When "Save formula" of the context menu is selected
Event Object Property
Property Name |
Type |
Description |
appId |
Number |
App ID |
recordIds |
Array |
Array of Record IDs |
records |
Array |
Array of record objects retaining the user input data |
type |
String |
Event type |
Control Depending on Field value
Event - After the Save Operation Is Performed
This event fires after the record has been successfully saved on the server. This event fires only once when multiple records are saved simultaneously. If saving fails, event isn't executed.
Multiple records can be obtained only from the data changed by the Records property of the event object.
If a Kintone.Promise object is returned, event processing starts upon the completion of asynchronous processing.
Event Type
app.record.index.edit.submit.success
Timing of Event Firing
- When record is successfully saved on server side
Event Object Property
Property Name |
Type |
Description |
appId |
Number |
App ID |
recordIds |
Array |
Array of Record IDs |
records |
Array |
Array of record objects retaining the user input data |
type |
String |
Event type |
Specifying Url Property
If the event is returned after specifying the url property in an event object, it will move to the URL concerned after event processing.
If the URL property isn't specified or Null is specified, it won't move and remain unchanged as a record view.
For example, if it's described as shown below, the screen will change to "https://krew.mescius.com/" after a successful save.
Sample Program |
Copy Code
|
// After a successful save operation, it will move to https://krew.mescius.com/.Kintone.events.on("app.record.index.show," function(e) {
krewSheet.events.on('app.record.index.edit.submit.success," function (event) {
event.url = "https://krew.mescius.com/";
console.log("url: " + event.url);
return event;
});
});
|
Control Depending on Field value
This function isn't available.
Sample
Sample Program |
Copy Code
|
// Display the time and date of update after saving the record
Kintone.events.on('app.record.index.show," function(e) {
krewSheet.events.on('app.record.index.edit.submit.success," function (event) {
var records = event.records;
for(let i=0; i<records.length;i++){
alert(tTime and date of update" + records[i]["time and date of update"]["value"] + ."");
}
// console.log(event);
return event;
});
});
|
Event - Upon starting the editing operation
This event fires when editing of knewSheet is started.
Event Type
app.record.index.edit.show
Event Object Property
Product Name |
Type |
Description |
appId |
Number |
App ID |
record |
Object |
Record objects retaining the data at the time when editing was started |
recordId |
Number |
Record ID |
type |
String |
Event type |
Control Depending on Field value
This function isn't available.
Event – Upon changing the field value
This event fires when the field value becomes modified. The modification of the value which triggered the event won't be canceled.
If a Kintone.Promise object is returned, event processing starts upon the completion of asynchronous processing.
Event Type
app.record.index.edit.change.<Field Code>
Fields That Can be Specified in Field Code
Handler can be performed only in the following situations: when field codes present in <Field Code> are specified; and the field types such as those shown below are specified. If any fields that aren't present in <Field Code> or field types other than those shown below are specified, no event will occur.
- Radio Button
- Drop-down
- Check box
- Multiple-choice
- User selection
- Department Selection
- Group selection
- Date
- Time
- Date and time
- Text (single-row)
- Number
- Table
*For Text (single-row) and Number fields, event fires at the following timing:
- When modified cell is moved
*For Table field, event fires at the following timing:
- When table rows are added and when the [Delete Row] button is clicked.
Event Object Property
Property Name |
Type |
Description |
appId |
Number |
App ID |
record |
Object |
Record object retaining the data input by user when event is fired |
recordId |
Number |
Record ID |
changes |
Object |
Changed object |
changes.field |
Object |
Changed Field object |
type |
String |
Event type |
Control Depending on Field value
Event-Before deleting a Record
This event fires after clicking the "Delete" button on the command bar and then "OK" on the popup menu. This event fires only once when multiple records are saved simultaneously.
If false is returned, the deletion process can be canceled. Multiple records can be obtained only from the data changed by the Records property of the event object.
If a Kintone.Promise object is returned, event processing starts upon the completion of asynchronous processing.
Event Type
app.record.index.delete.submit
Event Object Property
Program Name |
Type |
Description |
appId |
Number |
App ID |
recordIds |
Array |
Array of record ID |
records |
Array |
Array of record objects retaining record data to be deleted |
type |
String |
Event type |
Sample
When Kintone.Promise isn't used
Sample Program |
Copy Code
|
Kintone.events.on("app.record.index.show," function(e) {
krewSheet.events.on('app.record.index.delete.submit," function (event) {
var records = event.records;
if (!records[0]['Address']['value']) {
event.error = 'It can't be deleted because there is no address
';
}
return event;
});
});
|
Sample Program |
Copy Code
|
Kintone.events.on("app.record.index.show," function(e) {
krewSheet.events.on('app.record.index.delete.submit," function (event) {
var records = event.records;
// If there is no address, it returns false
if (!records[0]['Address']['value']) {
return false;
}
return event;
});
});
|
When kintone.Promise is used
Sample Program |
Copy Code
|
Kintone.events.on('app.record.index.show," function(event) {
krewSheet.events.on('app.record.index.delete.submit," function (event) {
var records = event.records;
var companyName = records[0]['Company name'].value;
// Confirm that company name exists in company master
var masterAppId = 923;
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) {
event.error = 'It can't be deleted because there is no Company name
';
}
return event;
});
});
});
|
Rewrite Field Value
If the handler rewrites the field value of the record object and returns the event object, then it updates the field value based on that rewritten value.
- If an empty string is specified in the radio button field, it becomes the default value choice.
- Rows can't be added to or deleted from the table.
- In the Event Upon Changing Filed Value (app.record.index.edit.change.<Field Code>), the value of a read-only field can't be rewritten. If you want to rewrite the value of read-only field, use the Event Before Executing Save Operation (app.record.index.edit.submit).
- In the Event Upon Changing Filed Value (app.record.index.edit.change.<Field Code>), only the values of displayed fields (including related sheet (table)) are rewriteable. If you want to rewrite the values of fields (include related sheet (table)) that aren't displayed, use the Event Before Executing Save Operation (app.record.index.edit.submit).
- If the field value was rewritten without any additional authority, it won't be reflected in the form.
- If the last handler doesn't return the value, the field value won't be updated.
- If multiple handlers are registered, the return value obtained from the last handler will be reflected.
Sample Program |
Copy Code
|
// At the time of field value change of "Drop-down_0," set "Text __1row" field as default value in "Text__1row__2" field of "Activity history"
Kintone.events.on("app.record.index.show," function(e) {
krewSheet.events.on('app.record.index.edit.change. Drop-down _0," function (event) {
var record = event.record;
record['Text __1row_']['value'] = 'Overwrite on this string ';
record['Activity history']['value'][0]['value']['Text__1row__2']['value'] = 'Overwrite first record in subtable';
return event;
});
});
|
Fields That Cannot be Rewritten
Regarding the following fields, even if the field value is rewritten and returned by the handler in Event Before Executing Save Operation, the rewritten value won't be reflected in the form.
- Record number
- Created by
- Created date/time
- Updated by
- Updated date/time
- Status
- Assignee
- Calculation
- Automatically calculated one string
- Attachment
- Lookup
- Lookup destination field
Displaying Error in Record
When the handler returns the event object after assigning an error message in the event object error, the rewriting operation of the field value is cancelled and the error is displayed in the row header.
Sample Program |
Copy Code
|
Kintone.events.on('app.record.index.show," function(event) {
krewSheet.events.on('app.record.index.edit.submit," function (event) {
event.records[0]['error'] = 'Show this error message';
return event;
});
});
|
Obtaining Changed Fields and Row Objects in Table
Changed fields can be obtained.
Sample Program |
Copy Code
|
Kintone.events.on('app.record.index.show," function(event) {
krewSheet.events.on('app.record.index.edit.change.Drop-down," function(event) {
var field = event.changes.field;
console.log(field);
return event;
});
});
|
Difference from Kintone Standard Event API
There are specific differences between knewSheet and Kintone standard event API:
|
Kintone |
krewSheet |
The record (s) property of the event object of the following events:
- krewSheet event before executing save operation(app.record.index.edit.submit)
- krewSheet event after successfully performing the save operation(app.record.index.edit.submit.success)
- krewSheet event before deleting a record(app.record.index.delete.submit)
|
Object
※Save / delete per record. |
Array of record objects
*Multiple records can be saved/deleted simultaneously. |
Showing the error message |
When a field error occurs, an error message will be displayed in the field. When a record error occurs, an error message will be displayed on upper part of the screen.
|
For both field and record errors, an error message will be displayed on the row header (left edge of the record) as well as on the footer.
|
Setting editable/non-editable upon event occurrence
|
When the handler returns the event object by assigning true/false to "disabled" of the record object field, that field will be non-editable/ enabled.
|
In krewSheet editable/non-editable can't be set upon event occurrence.
|
See Also