Running a script in expression tag

Hi everyone,
Im using an expression tag to pull some information from another memory tag dataset. I wrote a really basic script, and it does work (I tested it in the script console), however, when I go into the expression tag and write runScript("DataFunctions.get_W_Column", 1000, "path_to_tag"), I get an Error_ExpressionEval error and I have no idea why. Any and all help is appreciated.
Thanks!

My mistake, I also forgot to add the script I made.

def get_W_Column(tag_path):
	dataset = system.tag.read(tagPath).value

    # Check if dataset is empty or null
	if dataset is None or dataset.getRowCount() == 0:
		return "Dataset is empty or null"
	
	W_column = []
	for i in range(dataset.getRowCount()):
		W_column.append(dataset.getValueAt(i, dataset.getColumnIndex("W")))
	
	return W_column

Thanks again!

Iā€™m guessing Gateway Scripting Project.
Tags do not belong to a project, so they need to know where to look for scripts. This is done by setting a GSP on the gateway configuration page.

The only error I see is that your function takes tag_path as parameter, but you're passing tagPath to system.tag.read.

But you can improve a few other things here.
system.tag.read is obsolete, you should be using system.tag.readBlocking (or .readAsync)

You can get a dataset column with dataset.getColumnAsList(colu_index) instead of building it yourself.

Also, I'd advise against returning a string when the data is null. Just return None, that's what it means. If you need to display a message when there's no data, do it wherever that message should be displayed, but don't store it as a value.

All in all, the script can be written like this:

def get_W_Column(tag_path):
	dataset = system.tag.readBlocking(tag_path)[0].value
	if dataset is None or dataset.getRowCount() == 0:
		return None
	return dataset.getColumnAsList(dataset.getColumnIndex('W'))

Yea....I just realized that now. Unfortunately, I cannot change the setting on the gateway configure page. I dont have the permission. Is there a way where I can take the values from a column through an expression? For example, something like..toDataset(tag("my_tag_path")).getColumn("W")

Ask for whoever has the rights to that gateway to configure things properly or give you the rights to do it. It's unrealistic to expect people to work on ignition without being able to configure the gateway properly.

Thanks for the helpful advice! Im still learning to use ignition so this is very helpful.

Changing the GSP shouldn't be up for grabs.
If the configuration page is locked out, there are probably existing projects that depend on the GSP and would be broken by changing it.

Check out the possibility of: Scripting -> Gateway Events -> Tag Change
That will give you control of the script as part of your project

Hi Daniella,

What exactly are you trying to do here? It does look like you've been helped out on how to technically solve your problem, but I'm guessing we have an xy problem going on here.

It looks like you just want to get an array of values in column "W" of some dataset. You can do that right in the tag expression itself! This expression returns either a dataset with its columns rearranged, or an array of the column selected, if there was only one:

columnRearrange({[tag_provider]path_to_tag}, 'W')

In general, it's best practice to not do in a script (python) what can be done in an expression (built on Java). Meaning, whenever you find yourself wanting to use runScript(...), double check whether you need something python-specific, or if you can instead write an expression to do the work. It's more performant, and it can make your projects easier to debug (no need to go script hunting if the logic is already in the tag).

1 Like