getSize() returns wrong value

Hi all,

Why does getSize() returns 1 if there are no records in a table? See my sample code.
/** @type {JSFoundsetdb:/autoflex/dafldaid} */
var fs = databaseManager.getFoundSet(‘autoflex’, ‘dafldaid’);
for (var lnI = 0; lnI < vDetails.length; lnI++) {
var lcA2spId = vDetails[lnI].a2spid;
fs.search();
fs.a2spid = lcA2spId;
fs.find();
if (fs.getSize() == 0) {
\add a new record
Tia

Gerard Immeker

gerardimmeker:
Hi all,

Why does getSize() returns 1 if there are no records in a table? See my sample code.

/** @type {JSFoundset<db:/autoflex/dafldaid>} */

var fs = databaseManager.getFoundSet(‘autoflex’, ‘dafldaid’);
for (var lnI = 0; lnI < vDetails.length; lnI++) {
var lcA2spId = vDetails[lnI].a2spid;
fs.search();
fs.a2spid = lcA2spId;
fs.find();
if (fs.getSize() == 0) {
\add a new record


Tia

Gerard Immeker

Hi Gerard I think you have a little mistake. You are doing the search() before entering in find() mode.

You must do it like:

// You better always check if the foundset can enter in find mode.
// Otherwise if it cannot you will be changing data in the selected record.
if(fs.find()){
    fs.a2spid=lcA2spId;
    if(!fs.search()){
        \\ Add new records
    }
}else{
    // Foundset cannot enter in find mode. Maybe pending changes
}

Hi, Juan,

Thanks for your reply
That did the trick.

Gerard