key from new record

Questions and answers on designing your Servoy solutions, database modelling and other 'how do I do this' that don't fit in any of the other categories

key from new record

Postby nick1461658753 » Tue Nov 28, 2017 5:06 pm

Why does a foundset not return the key of a new record?

Code: Select all

FS.newRecord( );
FS.value1= "some value";
FS.value2=  "some other value";
FS.value3=  "another value";
databaseManager.saveData( FS );

CFS.FK= FS.id;


So I want to save the key of the new record in FS in a FK column in CFS. But FS.id is empty after the saveData. Why does it lose it's record after saving and why does it not automatically return the primary key after making a new record?
How can I get the id of FS easily and reliably to store in CFS?
How about pizza?
nick1461658753
 
Posts: 28
Joined: Tue Apr 26, 2016 10:19 am

Re: key from new record

Postby rafig » Thu Dec 07, 2017 2:29 pm

Hi
try doing a refresh of records from foundset and then get record one
Code: Select all
databaseManager.refreshRecordFromDatabase(FS, 1);
var rec = FS.getRecord(1) ;
CFS.FK= rec.id;


Rafi
Servoy Certified Developer
Image
rafig
 
Posts: 708
Joined: Mon Dec 22, 2003 12:58 pm
Location: Watford, UK

Re: key from new record

Postby juan.cristobo » Mon Dec 11, 2017 2:51 pm

Or try this:
Code: Select all
var rec = FS.getRecord(FS.newRecord());
rec.value1= "some value";
rec.value2=  "some other value";
rec.value3=  "another value";
databaseManager.saveData(rec);

CFS.FK= rec.id;
Juan
Madrid (Spain)

Servoy 7.4.x - MySQL / SQL Server 2008-2016
Windows 10 Pro
juan.cristobo
 
Posts: 186
Joined: Thu Apr 19, 2012 9:12 am


Return to Programming with Servoy

Who is online

Users browsing this forum: No registered users and 17 guests