Overwrite foundset.newRecord

Questions, tips and tricks and techniques for scripting in Servoy

Overwrite foundset.newRecord

Postby Roberto Blasco » Sat Jun 10, 2017 12:47 pm

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.
Un saludo. Roberto.

Madrid - Spain
Tfno: (+34) 625653066
E-mail: [email protected]
User avatar
Roberto Blasco
007
 
Posts: 341
Joined: Tue Apr 08, 2008 7:18 pm
Location: Madrid / Spain

Re: Overwrite foundset.newRecord

Postby Bernd.N » Sat Jun 10, 2017 7:41 pm

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.
Bernd Korthaus
LinkedIn
Servoy 7.4.9 SC postgreSQL 9.4.11 Windows 10 Pro
User avatar
Bernd.N
 
Posts: 477
Joined: Mon Oct 21, 2013 5:57 pm
Location: Langenhorn, North Friesland, Germany

Re: Overwrite foundset.newRecord

Postby jasantana » Sat Jun 10, 2017 7:59 pm

Have you tried the table events?
Best regards,
Juan Antonio Santana Medina
[email protected]
EAGER BEAVER 2011
EAGER BEAVER 2012
Servoy 6.x - Servoy 7.x - Servoy 8.x - MySQL - PostgreSQL - Visual Foxpro 9
User avatar
jasantana
 
Posts: 542
Joined: Tue Aug 10, 2010 11:40 am
Location: Leeds - West Yorkshire - United Kingdom

Re: Overwrite foundset.newRecord

Postby mboegem » Sat Jun 10, 2017 9:44 pm

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.
_____________________
Marc Boegem
Solutiative / JBS Group, Partner
• Servoy Certified Developer
• Servoy Valued Professional
• Freelance SAN Developer

Image
User avatar
mboegem
 
Posts: 1384
Joined: Sun Oct 14, 2007 1:34 pm
Location: Hoofddorp, The Netherlands

Re: Overwrite foundset.newRecord

Postby Roberto Blasco » Mon Jun 12, 2017 11:31 am

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.
Un saludo. Roberto.

Madrid - Spain
Tfno: (+34) 625653066
E-mail: [email protected]
User avatar
Roberto Blasco
007
 
Posts: 341
Joined: Tue Apr 08, 2008 7:18 pm
Location: Madrid / Spain


Return to Methods

Who is online

Users browsing this forum: No registered users and 4 guests

cron