Self.props.params.value does not exists, but it does exists (?)

This is the error:

Traceback (most recent call last): File "", line 7, in transform AttributeError: 'com.inductiveautomation.perspective.gateway.script' object has no attribute 'value'. It's ocurring on a binding of a embedded view.

The parameters to the embedded view are 3:

{
	"label": "text",
B	"value": 0,			# indirect path to tag
B	"color": "#cf7911"	# indirect path and script
}

The color script:

1 def transform(self, value, quality, timestamp):
2	value = system.util.jsonDecode(value) # value: [{"0":"#cf7911"},{"75":"#ffff00"},{"90":"#58d68d"}]
3	low = value[0]
4	med = value[1]
5	good = value[2]
6
7	current = self.props.params.value
8
9	if current < int(med.keys()[0]):
10		return low.values()[0]
11	elif current < int(good.keys()[0]):
12		return med.values()[0]
13	else:
14		return good.values()[0]

Dependes on the value of "value" to set red, green or yellow (or what is configured in the tag).
Sometimes, and only sometimes, the line 7 gives out an error.

No idea why the reference is failing...

Any idea?
Thx!

Note: I just notice that the binding is not set to persistent. Could this be?

Use the property browser to find the actual path to the param.

The one you have looks wrong. Try self.view.params.value

Also, may I say that this transform looks overly complex for what it does ?
Why is value a list containing single-value dicts, instead of just a dict ?
Why are you passing json instead of an actual data structure ?
Where does this value come from ?

Also, I suggest you use a structure binding and bind to both params instead of pulling the value in the transform.

This seems like an XY problem. That transform scripts looks like it shouldn't be a thing and that you should be using expressions instead, but I could be wrong.

I’m confused how your two snippets tie together, and about your setup in general. Can you use screenshots of the important pieces instead?

What is self ?

Typical usage would not have params as a child of props, but as a child of view. That is, self.view.params.value (unless self is a view).

1 Like

This was it. As I could see, the value param is not loaded when the script is getting executed and that is why it gives an error.

Also, the params value is to the Embedded View. Is not referenced wrong.

self ← The Embedded Component
.props ← Insidide the component
.params ← The category
.value ← The value that we pass as parameter

1 Like

If anyone is still curious I could show you what I'm doing. ^^

1 Like