Issue in writing into Dataset Tag

Hi All,

I have this dataset:

image

which I am trying to write on a dataset type tag on button action. The script on button action is this:

When I click on the button it shows this issue:

I have this tag on which Im tring to write

How to fix length issue?

That's not a dataset. That's a list of dictionaries.

You are giving writeBlocking() one tag path and two values in a list. It needs the same number of paths as values. (Using a string tagpath outside a list is a legacy support loophole--don't do that in new code.)

What kind of data are you trying to get as a result in your tag?

I am getting data from an API call which is list of dictionaries. I need this to be inserted into dataset tag. I was looking for a system dataset function for this case but have not found how to convert it.

You will probably have to roll your own conversion method for converting from the api response to a dataset.

A quick dirty conversion function:

def dictsToDataset(dicts, columns=None):
	""" """
	if not dicts:
		return system.dataset.toDataSet([], [[]])

	if not columns:
		columns = dicts[0].keys()

	data = [[item[column] for column in columns] for item in dicts]

	return system.dataset.toDataSet(columns, data)

Will probably work, but the dataset will make assumptions on the column types. If you need explicit control over the column data types, then make a function that uses the DatasetBuilder class to explicitly define the column types and build a dataset.

1 Like