Page 1 of 1

How can I modify the value of a field in all the rows of a DB Collection?

Posted: Tue Jun 24, 2014 5:03 pm
by Eduardo Orozco Sanchez

Hi.
I am trying to create a server script that increases the value within a field of a collection of the database for all of its rows when it is executed.
Eachvalue is an integer and I want the script to add a the same integer to each value.

For example,
Collection: Values:
Row: 1 Value: 100
Row: 2 Value: 200
Row: 3 Value: 50
Row 4 Value: 125

How can I add 125 to the value in each row and update de Collection?
I would like to update it to:
Row: 1 Value: 225
Row: 2 Value: 325
Row: 3 Value: 175
Row 4 Value: 250

So far I've used the Collection.updateObject command but it only allows me to update 1 row since it requires the row's id, how I can do this for all items in a database?

Thanks!


How can I modify the value of a field in all the rows of a DB Collection?

Posted: Tue Jun 24, 2014 5:32 pm
by Evgene Karachevtsev

Hello Eduardo,

You can't do this per one request. You can get all the records. You may come on them in the loop and update the value for each entry.


How can I modify the value of a field in all the rows of a DB Collection?

Posted: Tue Jun 24, 2014 5:40 pm
by Eduardo Orozco Sanchez

Thanks Evgene
Can you point me to a resource on how to create a loop in Appery?
I am getting started on this.
Thank you!


How can I modify the value of a field in all the rows of a DB Collection?

Posted: Tue Jun 24, 2014 6:14 pm
by Evgene Karachevtsev

Eduardo,

You can do this be using JS. Please look for info here: https://developer.mozilla.org/en-US/d...