Page 1 of 1

Overwrite foundset.newRecord

PostPosted: Sat Jun 10, 2017 12:47 pm
by Roberto Blasco
Hi all.

Is it possible to overwrite foundset.newRecord through application level or attach it a method?

What I wanna do is to do 'something' every time a new record is done in the database.

Thanks in advance.
Best regards. Roberto Blasco.

Re: Overwrite foundset.newRecord

PostPosted: Sat Jun 10, 2017 7:41 pm
by Bernd.N
When you have a button like one with a +-icon that creates a new record, then you could attach any code that you like to the new-record-event.
How are new records created in your case?

We use one generic method that runs all the time when a new record gets created, regardless for which table.
foundset.newRecord() is then just one tiny part of that record-creation-method which we named scopes.utils.recordAdd(...).

That method then takes care of everything that might be needed, like setting defaults, setting creation time and creation user, going into edit mode etc.
The advantage is that this method is generic, so you can put new abilities to it and it will effect all record creation events.

Re: Overwrite foundset.newRecord

PostPosted: Sat Jun 10, 2017 7:59 pm
by jasantana
Have you tried the table events?

Re: Overwrite foundset.newRecord

PostPosted: Sat Jun 10, 2017 9:44 pm
by mboegem
Hi Roberto,

you can not overwrite the newRecord function, but you can extend the foundset object of a particular table with your own functions using the entity scope.
You find this by opening the table in Servoy, select the 'method' tab and add functions (basically the same way as table events and calculations)

I often use a method initRecord(), something like this:
Code: Select all
/**
* @SuppressWarnings (wrongparameters)
*/
function initRecord() {
   newRecord(true);
   myTable_id = application.getUUID().toString();
   tenant_id = scopes.session.g_tenant_id;
   created_by = scopes.session.g_user_name;
   created_timestamp = new Date();
}


Since Servoy had some issues on code completion and warnings will appear on the newRecord step, I've added the SuppressWarnings JSDoc in order to get rid of the warnings.

Hope this helps.

Re: Overwrite foundset.newRecord

PostPosted: Mon Jun 12, 2017 11:31 am
by Roberto Blasco
Thanks all for your support :-)

Bernd.N

We use one generic method that runs all the time when a new record gets created, regardless for which table.
foundset.newRecord() is then just one tiny part of that record-creation-method which we named scopes.utils.recordAdd(...).


I am using the same method that you do .... but in my case I create one scope per table in which the methods are calling a generic one (emulating a Java Interface)

Code: Select all
scopes.my_tabla.insert(record){
scopes.db.insert(record);
}


jasantana
Have you tried the table events?


What I wanted to avoid is one event per table ..... lol

mboegem
you can not overwrite the newRecord function, but you can extend the foundset object of a particular table with your own functions using the entity scope.
You find this by opening the table in Servoy, select the 'method' tab and add functions (basically the same way as table events and calculations)


:shock: :shock: :shock: :shock:

I didn't know it was possible to extends from the foundset objet !!!!!! Love that feature.



So .... what I am gonna do is a mix of everything. Thanks all again to bright my mind !!!

Best regards. Roberto Blasco.