Save Button to Power Table

Hello! I want users to input three dimensions and have a 'Save' button that will save that information into a power table. I'm not sure how the scripting will work for this. Any help would be appreciated!

Ex. The user will type the width, pitch, and thickness then click on save which will then display and save the values into the power table below.

On the button's actionPerformed event, you'll want to use the system.dataset.addRow() function to your dataset. Keep in mind that this will create a whole new dataset (datasets cannot be modified in place) so you'll have to write the result back to your power table's dataset, whether that's a tag or just a bound value.

For a simplified example with only two numeric boxes and a dataset with only width and height:

width = event.source.parent.getComponent('WidthBox').intValue
height = event.source.parent.getComponent('HeightBox').intValue

current_data = #get your dataset from binding/tag here

new_data = system.dataset.addRow(dataset=current_data, row=[width, height])

#write your new_data to tag/binding here

Without more info on where the dataset for the power table comes from I can't really get into more detail

1 Like

Could I create a new database and have current_data = 'New database name'?

I'm not sure what you mean by power table dataset.

I mean the Data property on the power table that is bound to whatever data source for your table.

I originally thought you were doing a short-term storage using tags or properties. For storage you can set up a Named Query that INSERTs a row into the database and one that SELECTS the table (for binding to your power table)

The script would be pretty different for a database:

width = event.source.parent.getComponent('WidthBox').intValue
height = event.source.parent.getComponent('HeightBox').intValue

system.db.runNamedQuery(updateMaterials, {"width": width, "height": height})

You can then use a Named Query Binding to automatically update the power table from the same database.