Create dataset and assign to table data

I’m just trying to create some sample data for a Table.

Won’t this create a Dataset - Titled DP? (with just 5 rows of data)

headers = [“Date”, “Barrels”]

Then create an empty list, this will house our data.

data = []

Then add each row to the list. Note that each row is also a list object.

data.append([“2/27/19”, 67.85])
data.append([“2/28/19”, 72.36])
data.append([“2/29/19”, 62.5])
data.append([“3/1/19”, 70.98])
data.append([“3/2/19”, 75.25])

Finally, both the headers and data lists are used in the function to create a Dataset object

DP = system.dataset.toDataSet(headers, data)

How do I bind the Table to use this dataset?
Where is this dataset stored?

1 Like

In memory. You need to assign the tables dataset to it.
tbl = event.source.parent.getComponent(‘myActualTableName’)
tbl.data = DP

You also can click on the table, then in the properties pane, click on the icon that looks like a little table beside the data property. From there you can create a dataset without scripting it, however you still have to type the data.

I’m sorry, but you say in memory? This is my problem, I don’t know where I need to put this scripting
to make this happen.

Can you please explain for a beginner?

Thanks

If it is just for testing put it in on the action performed event of a button.

I must be missing something,

If I put this in the “Client Project Script” so that it executes when client project starts will this not create a “DATASET” tiltled DP?? I want this dataset to be available for the project.

It returns an error when typed as shown!!!

headers = [“Date”, “Barrels”]
data = []
data.append([“2/27/19”, 67.85])
data.append([“2/28/19”, 72.36])
data.append([“2/29/19”, 62.5])
data.append([“3/1/19”, 70.98])
data.append([“3/2/19”, 75.25])
DP = system.dataset.toDataSet(headers, data)
table = event.source.parent.getComponent(‘DPTable’)
table.data = DP

Now if I can ever get a DATASET created how do I bind it to the TABLE??? My table name is DPTable.

I must not be making myself clear.

I’m not sure if this is a function of how the code got from Ignition to forum post or an issue in your code, but the code as posted is using curly quotation marks that will throw an error. Put triple back ticks (```) on a line above and below your code in forum posts to make it format well like below. Here’s your code with curly quotation marks replaced. I used single quotation marks, but plain/straight double quotation marks would work as well. The code below will create a dataset like you’re looking for:

headers = ['Date', 'Barrels']
data = [['2/27/19', 67.85]]
data.append(['2/28/19', 72.36])
data.append(['2/29/19', 62.5])
data.append(['3/1/19', 70.98])
data.append(['3/2/19', 75.25])

The other issue is where to put this code. The client startup script event’s parent will not be the container holding the table. You would need to make sure the window is open, get a handle to the window, and then drill down to the table component. Instead, you could:

Assign the value to a memory tag and bind DPTable.data to the memory tag.

system.tag.write('dpData', DP)

Or put the script in the table’s event script like this:

1 Like

That’s Witman, for taking the time to help, I think I have made progress but still can’t get it working. I am still missing something.

I do have the script to create DATASET (Titled DP) in the propertyName event of (Container 1) - Maybe this script should go elsewhere?

So If the script does trigger and creates a DATASET called DP – My table called (DPTABLE) still does not bind to it.

Please see attached pictures

1 Like

You placed the script in the propertyChange event handler for the table, but then you are looking for the event.propertyName to be equal to ‘Container 1’. Unless I’m missing my guess this is never the case and so your script is not executing. Notice how @witman script is looking for event.propertyName to be equal to compoenentRunning.

Since you are generating this data set in a script you don’t need to bind the data property. Bindings are used to map external sources to properties, you’re script is an internal source.

1 Like

I must not be asking the correct question.

If I add a (Table Object) to my window and I name it (DPTable) how do I get it to show the data from this (DataSet) see picture (Note this scripts gives me an error.)

1 Like

I just ran this and it works. I created two tables, one named ‘table’ and one ‘DPTable’. In the propteryChange event in ‘table’ I used this code.

if event.propertyName == 'componentRunning': 
	headers = ['Date', 'Barrels']
	data = []
	data.append(['2/27/19', 67.85])
	data.append(['2/28/19', 72.36])
	data.append(['2/29/19', 62.5])
	data.append(['3/1/19', 70.98])
	data.append(['3/2/19', 75.25])
	DP = system.dataset.toDataSet(headers, data)
	table = event.source.parent.getComponent('DPTable')
	table.data = DP
1 Like

You have asked that question and it has been answered. There are differences between your script and the script that was given. I am sure that is where the issue lies.

When you define data you are using parenthesis where you should be using square brackets.

Also, you have parenthesis around the string comparison, which shouldn’t be hurting anything but is really not needed.

Both @witman and @dkhayes117 have provided scripts to do the task you’re wanting done.

If the script is giving an error, tell us what the error is and we will help you correct the issue.

1 Like

You have a capital ‘D’ on data on the last line of your script. Fix that. In the future, show your errors in full. (Use triple-’ formatting on those, too, just like code samples.)

1 Like

Oh, and screen shots are really annoying. But that’s just me. /-:

1 Like

Not just you... much easier to troubleshoot code I can copy and paste into the script console than from a screenshot (says the guy who just posted code in a screenshot). Showing full error is very helpful too.

@dcamp1 you've probably figured this out from feedback above, but if you paste the code below into the property change event of the table you want the data displayed in, it should work:

if event.propertyName = 'componentRunning':
	headers = ['Date', 'Barrels']
	data = [['2/27/19', 67.85]]
	data.append(['2/28/19', 72.36])
	data.append(['2/29/19', 62.5])
	data.append(['3/1/19', 70.98])
	data.append(['3/2/19', 75.25])
	DP = system.dataset.toDataSet(headers, data)
	event.source.data = DP
3 Likes

@witman and @pturmel, I bet you guys can see the matrix.

4 Likes

New Error.
‘’'Traceback (most recent call last):
File “event:propertyChange”, line 13, in
IndexError: Row 0 doesn’t have the same number of columns as header list.

at org.python.core.Py.IndexError(Py.java:250)
at com.inductiveautomation.ignition.common.script.builtin.DatasetUtilities.toDataSet(DatasetUtilities.java:489)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:186)
at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:204)
at org.python.core.PyObject.__call__(PyObject.java:404)
at org.python.core.PyObject.__call__(PyObject.java:408)
at org.python.pycode._pyx2.f$0(<event:propertyChange>:14)
at org.python.pycode._pyx2.call_function(<event:propertyChange>)
at org.python.core.PyTableCode.call(PyTableCode.java:165)
at org.python.core.PyCode.call(PyCode.java:18)
at org.python.core.Py.runCode(Py.java:1275)
at com.inductiveautomation.ignition.common.script.ScriptManager.runCode(ScriptManager.java:636)
at com.inductiveautomation.factorypmi.application.binding.action.ActionAdapter.runActions(ActionAdapter.java:180)
at com.inductiveautomation.factorypmi.application.binding.action.ActionAdapter.access$000(ActionAdapter.java:40)
at com.inductiveautomation.factorypmi.application.binding.action.ActionAdapter$ActionRunner.run(ActionAdapter.java:286)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

Ignition v7.9.10 (b2018112821)
Java: Oracle Corporation 1.8.0_201
‘’’

2 Likes

I finally have it working! I’m sorry for all the questions, I appreciate all of the help. As you can tell I’m learning so please be patient.

I will try to follow all the tips you provide.

Thanks again.

1 Like

Not relevant in this case as you’ve resolved it, but the error you posted refers to line 13 of your property change event code, so you’d want to post your code along with the error in the future for troubleshooting help (there aren’t 13 lines in the code we provided and we may be able to see the matrix, but can’t quite see your monitor–yet). Glad you got it figured out!

2 Likes