# Script works in designer, not in browser

**URL:** <https://forum.inductiveautomation.com/t/script-works-in-designer-not-in-browser/61840>\
**Category:** Ignition\
**Tags:** scripting, ignition81, perspective\
**Created:** [July 13, 2022, 11:51am UTC](https://forum.inductiveautomation.com/t/script-works-in-designer-not-in-browser/61840 "2022-07-13T11:51:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [July 13, 2022, 11:51am UTC](https://forum.inductiveautomation.com/t/script-works-in-designer-not-in-browser/61840/1 "2022-07-13T11:51:29Z")

</div>

Hello folks.

I come to you because I’m utterly confused as to what’s wrong with what I’m trying to do.

Here’s the full situation (in case the issue comes from something else than the script):  
I have a main view, with a value change script on its parameter. This script sends a message to broadcast the parameter’s new value:

```python
def valueChanged(self, previousValue, currentValue, origin, missedEvents):
	zone_num = currentValue.value
	system.perspective.sendMessage(
		messageType="page_changed",
		payload={'page': "zone", 'zone_num': zone_num}
	)

```

The point is to pass this parameter to docks. Which, I believe, is working fine.  
One of these docks has this message handler:

```python
def onMessageReceived(self, payload):
	if payload.get('page') in ["zone", ...]: # there are actual values here, not '...'
		self.view.custom.zone_num = payload.get('zone_num')

```

I display `zone_num` on the dock, it works, no problem here (again, I believe).

Now, on the dock’s view, I have another custom property, bound 3 properties including zone\_num (the others 2 are not supposed to change much), and with this script transform:

```python
def transform(self, value, quality, timestamp):
	try:
		ncu_name = next(z.ncu.name for z in value.devices if z.zone_num == value.zone)
	except StopIteration as e:
		return "ncu not found for zone {}".format(value.zone)
	return {
		'name': ncu_name,
		'alarms': value.alarms.get(ncu_name, 0)
	}

```

This works fine in the designer:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/0/d04d5a5801cb5547728cda9c03ac69755fdf6aa5.png) ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/6/a640c375fec6f9455772899a7cf4bc0c02a4458e.png) ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/d/8d03dec762ae85cf6d724ec57655bc773d513d66.png)

All of those are what I’d expect.

Now, when I try this in the browser… The first load shows the good results, I’m guessing because it just shows the defaults.  
But if I try to navigate to another zone page, either by changing the url manually or clicking links, it just doesn’t work, and trying to display the object with a label just shows “ncu not found for zone x”.  
Another label displays `zone_num` and it is correct.  
I also tried displaying the other 2 properties, `alarms` and `devices`, or at least their length, and they also seem correct.

I turned this around in any way I could think of, but I can’t figure it out. I’m completely clueless and have no idea what to even try anymore…  
I’ll take any help you wonderful people can provide !

edit: Wait I might be a moron and just forgot that `zone_num`, when coming from an url parameter, is a string.  
I guess I had to type all of this to think about that, huh.

edit 2: Yep, mystery solved. Move along, nothing to see here.

edit 3: I miss type hints.

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [July 13, 2022, 12:37pm UTC](https://forum.inductiveautomation.com/t/script-works-in-designer-not-in-browser/61840/2 "2022-07-13T12:37:14Z")

</div>

[Rubber duck debugging](https://en.wikipedia.org/wiki/Rubber_duck_debugging) does it again!

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [July 13, 2022, 12:54pm UTC](https://forum.inductiveautomation.com/t/script-works-in-designer-not-in-browser/61840/3 "2022-07-13T12:54:48Z")

</div>

I scratched my head for a few hours on this one. I’m glad you guys are enjoying my idiocy.

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [July 13, 2022, 1:00pm UTC](https://forum.inductiveautomation.com/t/script-works-in-designer-not-in-browser/61840/4 "2022-07-13T13:00:40Z")

</div>

I got a few posts in my history that follow the same story you did where I figured out my own (in retrospect) obvious mistake. I’m not enjoying your idiocy, it just makes me feel more comfortable with my own 🙂
