DOM API example - looping through user selected rows and manually building a TransactionSet

19 views
Skip to first unread message

Robert

unread,
Nov 16, 2017, 10:05:05 AM11/16/17
to ParaSQL Support
The following ParaSQL DOM API function is called when the user clicks a button (via a click event on that button).
This fairly complex example loops through a list of records to see which ones the user has selected, and based on that and the Adjust By Qty virtual field builds an entirely new record set to update rows (potentially thousands) by the specified amount.


function adjustComponentQtyBy(event) {
var ts = new parasql.schema.TransactionSet();
var ft_bom_components = ts.addNewDataTable('ft_bom_components');
ft_bom_components.addNewColumn('mfg_item_id','int').setPrimaryKeyMember(true);
ft_bom_components.addNewColumn('component_item_id','int').setPrimaryKeyMember(true);
ft_bom_components.addNewColumn('component_qty','int');
var sourceDT = parasql.app.getWidgetById('ID2627').getDataTable();
var mfgItemIdColIndex = sourceDT.getIndexOf('mfg_item_id');
var componentItemIdColIndex = sourceDT.getIndexOf('component_item_id');
var componentQtyColIndex = sourceDT.getIndexOf('component_qty');
var adjByQty = parasql.app.getWidgetById('ID2633').getDataValue().getNumber();
var rows = sourceDT.getRows();
for (var i = 0; i < rows.length; i++) {
if (rows[i].getIsSelected() == true) {
var newRow = ft_bom_components.appendNewRow();
newRow.getValueAt(0).setNumber( rows[i].getValueAt(mfgItemIdColIndex).getNumber() );
newRow.getValueAt(1).setNumber( rows[i].getValueAt(componentItemIdColIndex).getNumber() );
newRow.resetChangeTracker(); // primary keys exist, only updating values that follow
// adjust the component qty by the specified amount
newRow.getValueAt(2).setNumber( rows[i].getValueAt(componentQtyColIndex).getNumber() + adjByQty );
}
}
alert('Will modify this many rows in ft_bom_components: '+ft_bom_components.getRows().length);
// save it
ts.save();
}



Robert

unread,
Nov 16, 2017, 10:26:00 AM11/16/17
to ParaSQL Support
The description above should read more like this:

The following function (which would be located in the application's Script Library) is called when the user clicks a button in the UI (via a click event on that button).
This example uses the ParaSQL DOM API to loop through a list of records to see which ones the user has selected, and based on that and the Adjust By Qty virtual field builds an entirely new record set to update rows (potentially thousands) by the specified amount.

Reply all
Reply to author
Forward
0 new messages