Boost!for kintone
HOW TO WRITE

How to write event processing

This section introduces how to register event handlers to events and how to remove them.

01

Register an event handler

Syntax
bst.event.on(type, handler)
Parameters
Parameter Value Description
type String or array of strings

Specify the event type, or an array of event types, to which the event handler is bound.

handler Function

The handler that runs when the event occurs.

If you return a Promise object in the event handler, the next process starts after the asynchronous process is complete.

Return value
None.
Sample
(() => {
	"use strict";
	const handler = (event) => {
		console.log(event);
	};
	bst.event.on('bst.view.load', handler);
})();
02

Remove an event handler

Syntax
bst.event.off(type, handler)
Parameters
Parameter Value Description
type String or array of strings

Specify the event type, or an array of event types, to which the event handler to remove is bound.

handler Function

The event handler to remove. Specify the same event handler as when it was bound.

Return value
None.
Sample
(() => {
	"use strict";
	const handler = (event) => {
		console.log(event);
	};
	bst.event.on('bst.view.load', handler);

	bst.event.off('bst.view.load', handler);
})();
EVENT OBJECT

Operations you can perform with the event object

This section introduces the operations you can perform with the event object in an event handler.

01

Rewrite field values

If you rewrite field values of the record object in the event handler and return the event object, the field values of the record are updated.

Sample
(() => {
	"use strict";
	bst.event.on('bst.change.field_1_', (event) => {
		const record = event.record;
		if (record.field_1_.value=='')
		{
			record.field_2_.value='option1';
		}
		return event;
	});
})();
02

Retrieve a lookup automatically

If you set the lookup property of a lookup field to true in the event handler and return the event object, the value of that lookup field is retrieved automatically.

To clear a lookup field, empty the value property and set the lookup property to true.

Sample
(() => {
	"use strict";
	bst.event.on('bst.edit.load', (event) => {
		const record = event.record;
		if (!record.field_3_.value)
		{
			record.field_3_.value=1;
			record.field_3_.lookup=true;
		}
		return event;
	});
})();
03

Stop the subsequent processing

If you set the error property to true in the event handler and return the event object, the operation, including the subsequent processing, is canceled.

Sample
(() => {
	"use strict";
	bst.event.on('bst.create.submit', (event) => {
		const record = event.record;
		if (record.field_1_.value=='')
		{
			bst.alert('No value entered.');
			event.error=true;
		}
		return event;
	});
})();