I have been trying to insert a new record in my database.
My code is as follows:
// Create new record
var idx = forms[formName].foundset.newRecord();
var record = forms[formName].foundset.getRecord(idx);
// Get record from where to copy data
var fsProfile = databaseManager.getFoundSet( “DatabaseName”, tableName )
var whrString = “'”+whereKey+“'”
var _queryProfile =‘Select "’+pkId+‘" from "’+tableName+‘" where "’+pkId+‘" =’+whrString
application.output(‘Select "’+pkId+‘" from "’+tableName+‘" where "’+pkId+‘" =’+whrString)
var _argsProfile = new Array()
fsProfile.loadRecords(_queryProfile,_argsProfile)
var dprovider = ‘’
for(var i = 0; i < fsProfile.alldataproviders.length; i++) {
dprovider = fsProfile.alldataproviders // keyDataProvider is my primary key
}* Now when I check my record in the database, all values are getting updated as expected but when I try to retrieve the primary key value by using
returnVal = record.foundset.getDataProviderValue(keyDataProvider);* OR returnVal = record[keyDataProvider] it is returning , even though the value is set in the new record (verified by checking the database). I even tried using record = forms[frmObject].foundset.getRecord(idx); before retrieving the primary key value so as to refresh the contents of ‘record’ but still no luck. Any workaround for this?
Thanks, but I have already tried this. The problem is that the contents of ‘record’ variable are not getting updated with the values which are not explicitly saved but are generated using triggers. So my database has all the correct values saved in it but the variable ‘record’ doesn’t get updated with those values.
var saved_rec = databaseManager.saveData(record);
if (saved_rec) {
databaseManager.refreshRecordFromDatabase(record, 1);
} else {
log_message('Failed to Save Record', 'ERROR');
}
EDIT: I cross checked the Primary Key value from my table. This code is actually returning the primary key of the parent record which I am using for duplication instead of the primary key of the duplicated record
I cross checked the Primary Key value from my table. This code is actually returning the primary key of the parent record which I am using for duplication instead of the primary key of the duplicated record
What I am doing is :
var saved_rec = databaseManager.saveData(record);
if (saved_rec) {
databaseManager.refreshRecordFromDatabase(record.foundset, 1);
} else {
application.output(‘Failed to Save Record’);
}
var retrunVal = record.foundset.getDataProviderValue(keyDataProvider)
If I write
databaseManager.refreshRecordFromDatabase(record, 1);
Hi,
unless you really have to, don’t do things using ‘forms’, try to do it in memory as it’s easier & more efficient
so I am doing something like this
/** @type {JSFoundSet<db:/dbserver/mytable>} */
var fs = databaseManager.getFoundSet('db:/dbserver/mytable');
/** @type {JSRecord<db:/dbserver/mytable>} */
var record1;
/** @type {JSRecord<db:/dbserver/mytable>} */
var record2;
// create 1st record
record1 = fs.getRecord(fs.newRecord());
var saved_rec = databaseManager.saveData(record1);
if (saved_rec) {
databaseManager.refreshRecordFromDatabase(fs, 1); // as we created default new record, it will be 1 in foundset
} else {
application.output ('Failed to Save');
}
// now do what you need to set up record2
// then you can access record 1 PK using
record2.fk = record1.pk ;
or something like that, but hope that gives you an idea
var fs = databaseManager.getFoundSet(‘db:/DatabaseName/’+ tableName);
var record = fs.getRecord(fs.newRecord());
// Get record from where to copy data
var fsProfile = databaseManager.getFoundSet( “DatabaseName”, tableName )
var whrString = “'”+whereKey+“'”
var _queryProfile =‘Select "’+pkId+‘" from "’+tableName+‘" where "’+pkId+‘" =’+whrString
application.output(‘Select "’+pkId+‘" from "’+tableName+‘" where "’+pkId+‘" =’+whrString)
var _argsProfile = new Array()
fsProfile.loadRecords(_queryProfile,_argsProfile)
var dprovider = ‘’
for(var i = 0; i < fsProfile.alldataproviders.length; i++) {
dprovider = fsProfile.alldataproviders // keyDataProvider is my primary key if(dprovider != keyDataProvider) { record[dprovider] = fsProfile[dprovider] } } var saved_rec = databaseManager.saveData(record); if (saved_rec) { databaseManager.refreshRecordFromDatabase(fs, 1) } else { application.output(‘Failed to Save Record’); } application.output(record[keyDataProvider]) Still getting
I guess the whole issue lies in the fact that when I perform the action databaseManager.refreshRecordFromDatabase(foundset,index), my record in the foundset gets shuffled since there are no fixed indexes of records in the foundset and then when I try to retrieve the contents of my record using the old, original index value I get some other record altogether. If only there was some way to refresh just the record or refresh the foundset while retaining the value of the record’s index.