# In memory FoundSet update a column

**URL:** <https://forum.servoy.com/t/in-memory-foundset-update-a-column/18933>\
**Category:** Classic Servoy\
**Created:** [August 8, 2016, 11:22am UTC](https://forum.servoy.com/t/in-memory-foundset-update-a-column/18933 "2016-08-08T11:22:33Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeffrey.vandenhondel](https://avatars.discourse-cdn.com/v4/letter/j/ed8c4c/32.png) [@jeffrey.vandenhondel](https://forum.servoy.com/u/jeffrey.vandenhondel)\
**Post date:** [August 8, 2016, 11:22am UTC](https://forum.servoy.com/t/in-memory-foundset-update-a-column/18933/1 "2016-08-08T11:22:33Z")

</div>

Hello,

I want to update one column in my memory foundset without updating the whole foundset.  
Is this possible?

Kind regards.

---

<div class="post-metadata">

**Author:** ![Bernd.N](https://avatars.discourse-cdn.com/v4/letter/b/7feea3/32.png) [@Bernd.N](https://forum.servoy.com/u/Bernd.N)\
**Post date:** [August 9, 2016, 2:42pm UTC](https://forum.servoy.com/t/in-memory-foundset-update-a-column/18933/2 "2016-08-09T14:42:21Z")

</div>

Hi Jeffrey,

as far as I know, a foundset is always something in memory, as it represents a (desired / filtered) subset of the physical database table.  
(There can be a foundset without physical table, but I guess that is not something you had in mind.)

Maybe you want to say “I want to update one column in my memory foundset without updating the whole table.” ?

In that case you would loop through the foundset, which would look like this.  
Note that the getSize() function in the for loop will make sure that all records will be changed, and not only the first 200 (or 70 or whatever) in the foundset which will be loaded initially.

```auto
for (i = 1; i <= fs.getSize(); i++) {
		
	rRec = fs.getRecord(i);

	rRec.yourFieldName = "yourNewValue";
}

```

My personal preference is to not use such a loop in cases where I have to update a lot of records (which happens seldom), as they are slower than SQL, but to use just plain SQL UPDATES inside Servoy, like this (sSQL contains the SQL-Query-String):

```auto
plugins.rawSQL.executeSQL(scopes.utils.DB.SERVER, null, sSQL);

```

---

<div class="post-metadata">

**Author:** ![jeffrey.vandenhondel](https://avatars.discourse-cdn.com/v4/letter/j/ed8c4c/32.png) [@jeffrey.vandenhondel](https://forum.servoy.com/u/jeffrey.vandenhondel)\
**Post date:** [August 9, 2016, 2:49pm UTC](https://forum.servoy.com/t/in-memory-foundset-update-a-column/18933/3 "2016-08-09T14:49:06Z")

</div>

Hi Bernd,

We are using a foundset without a physical table.  
Tomorrow i will try the for loop i will let you know if it worked.

---

<div class="post-metadata">

**Author:** ![Bernd.N](https://avatars.discourse-cdn.com/v4/letter/b/7feea3/32.png) [@Bernd.N](https://forum.servoy.com/u/Bernd.N)\
**Post date:** [August 9, 2016, 2:57pm UTC](https://forum.servoy.com/t/in-memory-foundset-update-a-column/18933/4 "2016-08-09T14:57:04Z")

</div>

Ok, in that case you would have a specific IF-condition that you use inside the loop.  
Only when that IF is true, a record of the foundset will get changed.  
But you would loop through the complete foundset to inspect all records.

---

<div class="post-metadata">

**Author:** ![marco.rossi](https://avatars.discourse-cdn.com/v4/letter/m/58f4c7/32.png) [@marco.rossi](https://forum.servoy.com/u/marco.rossi)\
**Post date:** [August 10, 2016, 3:42pm UTC](https://forum.servoy.com/t/in-memory-foundset-update-a-column/18933/5 "2016-08-10T15:42:14Z")

</div>

Dear jeffrey,

Have you already tried with the foundsetUpdater?

It’s very fast. Y  
You can use it as follow:

```auto
var updater = databaseManager.getFoundSetUpdater(foundsetYouWantToUpdate)
     updater.setColumn("columnName","valueYouWantToInser")
     updater.performUpdate()

```

I haven’t used it to update a foundset not linked to any table but it should work anyway.

Regards

Marco

---

<div class="post-metadata">

**Author:** ![jeffrey.vandenhondel](https://avatars.discourse-cdn.com/v4/letter/j/ed8c4c/32.png) [@jeffrey.vandenhondel](https://forum.servoy.com/u/jeffrey.vandenhondel)\
**Post date:** [August 11, 2016, 7:15am UTC](https://forum.servoy.com/t/in-memory-foundset-update-a-column/18933/6 "2016-08-11T07:15:11Z")

</div>

> Bernd.N:  
> Ok, in that case you would have a specific IF-condition that you use inside the loop.  
> Only when that IF is true, a record of the foundset will get changed.  
> But you would loop through the complete foundset to inspect all records.

Thank you very much!!  
I fixed it with a foundset filter.

This is how i coded the function.

```auto
fs.addFoundSetFilterParam('print_or_email', '=', 0, 'filterPrintOrEmail');
fs.loadAllRecords();

```

> marco.rossi:  
> Dear jeffrey,
> 
> Have you already tried with the foundsetUpdater?
> 
> It’s very fast. Y  
> You can use it as follow:
> 
> ```auto
> var updater = databaseManager.getFoundSetUpdater(foundsetYouWantToUpdate)
> 
> ```

```
 updater.setColumn("columnName","valueYouWantToInser")
 updater.performUpdate()

```

> ```auto
> 
> I haven't used it to update a foundset not linked to any table but it should work anyway.
> 
> Regards
> 
> Marco
> 
> ```

I did try it like that but it didn’t update as i wanted ![:)]( "Smile")

---

<div class="post-metadata">

**Author:** ![Bernd.N](https://avatars.discourse-cdn.com/v4/letter/b/7feea3/32.png) [@Bernd.N](https://forum.servoy.com/u/Bernd.N)\
**Post date:** [August 11, 2016, 2:10pm UTC](https://forum.servoy.com/t/in-memory-foundset-update-a-column/18933/7 "2016-08-11T14:10:10Z")

</div>

There is an article from Gary regarding looping through foundsets that might be interesting for you:

```auto
http://www.dotzlaw.com/tutorials/servoy-tutorials/servoy-tutorial-optimizing-code-performance/

```
