Hello,
I need to update some related line items fields with a loop??, and am getting a little confused.
I have 2 columns
Allocated_stock = 100
Committed_stock = 0
What a want to do is loop through all related records and update the committed_stock column with the Allocated_stock value. then set the allocated_stock column to 0. Is it possible to update/change fields this way with the databaseManager.getFoundSetUpdater command.
I have tried the following with no luck
var fsUpdater = databaseManager.getFoundSetUpdater(Related Foundset)
fsUpdater.setColumn('Allocated_stock',Committed_stock)
fsUpdater.setColumn('Allocated_stock',0)
fsUpdater.performUpdate()
Many thanks
You cannot use fsUpdater.setColumn(…) in this way - it only fills all the specified records with one and the same value - the second parameter (in your code snippet 0 or the value of the selected record’s “Committed_stock” column).
It is helpful to easily set entire columns to constant values or to values calculated based on the number of iterations (if you use next()) for example (see the Servoy Developer Reference Guide).
wvitpr:
… then set the allocated_stock column to 0. Is it possible to update/change fields this way with the databaseManager.getFoundSetUpdater command…
So only half of what you wanted is easily done using FoundSetUpdater.
var fsUpdater = databaseManager.getFoundSetUpdater(Related Foundset)
fsUpdater.setColumn('Allocated_stock',0)
fsUpdater.performUpdate()
why don’t you just loop as you say?
for ( var i = 1; i <= your_relation.getSize() ; i++) {
var vRelatedRecord = your_relation.getRecord(i);
vRelatedRecord.commited_stock = vRelatedRecord.allocated_stock;
vRelatedRecord.allocated_stock = 0;
}
databaseManager.saveData()
done.