Event

Last updated 7 months ago

Event

Event is a database table event that can also be written in JavaScript. (In database terminology it is called trigger)

Let's add an event to our table.

Select the table, select events, and click new.

Configure the event and write its code.

/* Rhino code */
var q=$iwb.sqlQuery('select count(1) xxx from x_person');
var cnt=1*q[0].get('xxx');
var result=false;
if(cnt>2)
result='Max Allowed Users=10, Current='+cnt;

This event is triggered before any insert action and if an action tries to insert 3rd record in database table then it will be stopped by the event with a message.

Don't forget to make the event active!

As you see in the image below there are 2 records. User cannot add another record.

This event can also be written in SQL:

select 'Max Allowed Users=10, Current='||x.cnt as result
from (select count(1) cnt from x_person) as x where x.cnt>2

If query returns result, the action that user wants to perform will be stopped with a message.