So basically every time the OK button is pressed, a new row should appear with new values.
The table has 23 columns whereas I want to update only 10 columns as the operator enters only these 10 values.
Originally, what I wanted to do was to bind each field to one memory tag and then use those tags in a table on another view, then at the same time I wanted to update the database based on the new values entered into the fields, but I thought this would not be the easiest way to do (I am not sure tho).
Now what I am doing is to use a query dataset tag to read from the database and by entering numbers into the fields, the query tag has to be updated, or at least I want the table to be updated.
I would appreciate any help or information you could give me. Thank you!
its usualy not a good idea to bind those kinda input fields to tags, as multiple clients could be running and that is going to be very messy with tags if multiple people are working on it…
however the table can be bound with a dataset tag.
and then on the button onaction script you can write to set dataset which will update the table for all users.
you’ll jsut have to add in default values for the empty columns for a dataset to work i guess.
You can also just directly write to the database and do a refreshBinding('props.data') on the table for it to pull the new data.
in the button script you should :
first read the dataset from the tag,
then do an system.dataset.addRow() with all the values in
and then write it back to the tag.
after that you should put the refreshBding in the button but point to the table
like
This is the first time I am using this script in perspective as I am new to using perspective so I am not sure how to use addRow in a database and could not find anything similar to get a good understanding of it as well.
So I wrote this which I am 100% sure is not correct.
# 1. Read the dataset from the tag (this should returns 23 columns)
newrow = system.tag.readAsync("[default]ms/Test/QueryTag.value")
# 2. addRow to dataset
dataset=system.dataset.addRow(dataset, newrow)
#3. Writing back to the tag
System.tag.writeAsync("[default]ms/Test/QueryTag.value",'dataset')
#4. Refresh Binding on the table
self.parent.parent.parent.parent.parent.getSibling("Melt").getChild.getchild("Table").props.data
I am sure the script is not correct at all, but I am not able to understand the process very well, as this is a dataset and is not a single number I am kind of confused about how to update the dataset.
You can do this by creating a named query with an SQL insert statement, then executing the named query on your button event. You would need to pass each one of the values of the popup to the named query as a parameter. You may need to refresh your table after aswell.
Writing the script below in the query section:
INSERT INTO table_name ( column1 , column2 , column3 , …)
VALUES ( value1 , value2 , value3 , …)
the values should be parameters? Not sure what to put here as values as named querries does not accept tags.
#1 define your row values into a list:
newRow = [Var1,Var2,Var3,VarX,VarY...]
#If your dataset has 23 columns, this should have 23 values,
#even if they're empty.
# 2. Get your dataset:
dataset= system.tag.readAsync("[default]ms/Test/QueryTag.value")
#3. Alter your dataset:
dataset = system.dataset.addRow(dataset,dataset.getRowCount()+1,newRow)
#The second argument is to make sure that your new row goes to the bottom
#You can change that if you want.
#4. Write it back to your tag:
System.tag.writeAsync("[default]ms/Test/QueryTag.value",dataset)
#5. Refresh Binding on the table
self.parent.parent.parent.parent.parent.getSibling("Melt").getChild.getchild("Table").props.data
But, if it’s not possible to write to a database by altering a dataset tag, this should’t work then.
Thank you very much for your valuable time.
In this example, Var1…VarY are values from the text field or the dataset column names?
It should be the text field values, but I have only 10 fields, which means that I have to put an empty string or 0 instead of the remained 13 columns, correct?
That would depend on if your table can accept nulls, in my example they are all required. I believe it would execute with no input on fields that allow null.
They’re values from the text field on the order that correspond to the order of the columns on the dataset.
If you have a dataset with four columns named “Time”, “PostalCode”, “Number” and “Place” and you don’t want to populate the last one your newRow should look like this:
newRow = [“26/09/1998 17:57”, Null,47,“BR”]
I’m not sure if Ignition would accept a straight up Null value, but if the column type it’s a string you could use “”
josborn is right when editing the table directly, i was referring to specifically when you're working with datasets, then you should pass the Nulls yourself.
This is the script I used (it did not accept Null):
# define values:
Var1='self.parent.parent.getChild("Melt").getChild("TextField").props.text'
Var2=...
Var3=...
Var4=...
Var5=...
Var6=...
Var7=...
Var8=...
Var9=...
Var10=...
#1 define the row values into a list:
newRow = [Var1, Var2, Var3, Var4, Var5, Var6, Var7, Var8, Var9, Var10, "", "", "", "", "", "", "", "", "", "", "", "", ""]
# 2. Get the dataset:
dataset= system.tag.readAsync("[default]ms/Test/QueryTag.value")
#3. Alter the dataset:
dataset = system.dataset.addRow(dataset,dataset.getRowCount()+1,newRow)
#The second argument is to make sure that your new row goes to the bottom
#You can change that if you want.
#4. Write it back to your tag:
System.tag.writeAsync("[default]ms/Test/QueryTag.value",dataset)
#5. Refresh Binding on the table
self.parent.parent.parent.parent.parent.getSibling("Melt").getChild.getchild("Table").props.data
# define values:
Var1='self.parent.parent.getChild("Melt").getChild("TextField").props.text'
Var2=...
Var3=...
Var4=...
Var5=...
Var6=...
Var7=...
Var8=...
Var9=...
Var10=...
#1 define the row values into a list:
newRow = [Var1, Var2, Var3, Var4, Var5, Var6, Var7, Var8, Var9, Var10, "", "", "", "", "", "", "", "", "", "", "", "", ""]
# 2. Get the dataset:
dataset= system.tag.readBlocking("[default]ms/Test/QueryTag.value")
#3. Alter the dataset:
dataset = system.dataset.addRow(dataset,dataset.getRowCount()+1,newRow)
#The second argument is to make sure that your new row goes to the bottom
#You can change that if you want.
#4. Write it back to your tag:
System.tag.writeAsync("[default]ms/Test/QueryTag.value",dataset)
#5. Refresh Binding on the table
self.parent.parent.parent.parent.parent.getSibling("Melt").getChild.getchild("Table").props.data