Page 1 of 1

Foundset

PostPosted: Mon May 15, 2017 12:30 pm
by dekumar2
Hi all, I want to change value of the data in foundset how can i change?

Re: Foundset

PostPosted: Mon May 15, 2017 12:32 pm
by ROCLASI
Hi,

You can simply set the value like so:
Code: Select all
foundset.myColymnName = 'new value';

// making sure the data is saved to the database
databaseManager.saveData(foundset);


Hope this helps.

Re: Foundset

PostPosted: Mon May 15, 2017 4:08 pm
by Bernd.N
And in case you are in the js-script of a form and you want to change the current record of that form, you can omit "foundset." at the front.

saveData() is needed especially when you need to be sure that the data is saved at once, e.g. because something else depends on it at once.
Otherwise, Servoy will save it automatically later.

When you want to change all the data in a foundset and not only the current record, that's a complete other story.
You have to iterate over it, see for example
https://wiki.servoy.com/display/public/DOCS/The+Servoy+Foundset#TheServoyFoundset-UsingtheFoundsetIterator

But not with forEach(), but with code like
Code: Select all
var
   i=0,
   rec=null;

for( i=1; i <= foundset.getSize(); i++ ) {

   rec = foundset.getRecord(i);

   rec.fieldName = rec.fieldName + 'newValue';

Re: Foundset

PostPosted: Tue May 16, 2017 4:25 pm
by marco.rossi
Hi Dekumar,

you can also use a foundsetUpdater if you have to change data massively:

Code: Select all
var _updater = databaseManager.getFoundSetUpdater(foundsetToUpdate)

   if() {
      _updater.setColumn("your_column",1)
   }else{
                _updater.setColumn("your_column",0)
        }
_updater.performUpdate()


Keep in mind that in this way you are changing all rows present within the foundset.