Foundset

Hi all, I want to change value of the data in foundset how can i change?

Hi,

You can simply set the value like so:

foundset.myColymnName = 'new value';

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

Hope this helps.

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

var
   i=0,
   rec=null;

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

   rec = foundset.getRecord(i);

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

Hi Dekumar,

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

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.