# Navigation script not executing, ideas?

**URL:** <https://forum.inductiveautomation.com/t/navigation-script-not-executing-ideas/63940>\
**Category:** Ignition\
**Tags:** perspective, ignition81\
**Created:** [September 9, 2022, 9:09pm UTC](https://forum.inductiveautomation.com/t/navigation-script-not-executing-ideas/63940 "2022-09-09T21:09:27Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![mjohnson0238](https://avatars.discourse-cdn.com/v4/letter/m/4bbf92/32.png) [@mjohnson0238](https://forum.inductiveautomation.com/u/mjohnson0238)\
**Post date:** [September 9, 2022, 9:09pm UTC](https://forum.inductiveautomation.com/t/navigation-script-not-executing-ideas/63940/1 "2022-09-09T21:09:27Z")

</div>

This script looks like it should be executing the navigation, but its not. It is executing everything up to that point. It will even execute the navigation outside of the “if”, any ideas would be great.

```auto
import time
	if origin == 'Browser':
		
		wand_num = self.getSibling("TextField").props.text
		scanner_id = self.session.custom.scanner_id
		
		system.tag.writeBlocking('[default]ABS Concentrate System/Barcode_Scanner/_'+str(scanner_id)+'_/Machine_ID', wand_num)
		time.sleep(2)
		status_word = system.tag.readBlocking('[default]ABS Concentrate System/Barcode_Scanner/_'+str(scanner_id)+'_/Status_Word')
		
		
		if status_word == 1:
			self.session.custom.scanner_id = wand_num
			self.getSibling("Label_1").meta.visible = 'true'
			time.sleep(1)
			system.perspective.navigate('/wandscan')
			
			
			
		else:
			self.getSibling("BadMachine").meta.visible = 'true'
			self.getSibling("TextField").props.text = ''
			self.getSibling("Label_1").meta.visible = 'false'

```

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [September 9, 2022, 11:02pm UTC](https://forum.inductiveautomation.com/t/navigation-script-not-executing-ideas/63940/2 "2022-09-09T23:02:08Z")

</div>

The tab position isn’t correct, but I’m assuming it just pasted into the forum that way.

a couple of ideas off the top of my head:  
Try: `if str(origin) == 'Browser'`

also try temporarily displaying origin somewhere [ie a label], just to make sure it is returning the expected value

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [September 10, 2022, 2:10pm UTC](https://forum.inductiveautomation.com/t/navigation-script-not-executing-ideas/63940/3 "2022-09-10T14:10:08Z")

</div>

Is there any error being logged to the Gateway? Is _any_ of the code within the `if` statement being executed? Actually, which `if` is the problem?

Also, `meta.visible` expects a boolean `True`/`False` instead of string `"true"`/`"false"`.

---

<div class="post-metadata">

**Author:** ![MMaynard](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mmaynard/32/3366_2.png) [@MMaynard](https://forum.inductiveautomation.com/u/MMaynard)\
**Post date:** [September 10, 2022, 2:45pm UTC](https://forum.inductiveautomation.com/t/navigation-script-not-executing-ideas/63940/4 "2022-09-10T14:45:27Z")

</div>

> [@mjohnson0238](#):
>
> `status_word = system.tag.readBlocking('[default]ABS Concentrate System/Barcode_Scanner/_'+str(scanner_id)+'_/Status_Word')`

You need to put .value on the end of that.  
system.tag.readBlocking returns a QualifiedValue

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [September 10, 2022, 3:42pm UTC](https://forum.inductiveautomation.com/t/navigation-script-not-executing-ideas/63940/5 "2022-09-10T15:42:58Z")

</div>

A list of qualified values. So, add `[0].value`.

---

<div class="post-metadata">

**Author:** ![deon.korb](https://avatars.discourse-cdn.com/v4/letter/d/8c91f0/32.png) [@deon.korb](https://forum.inductiveautomation.com/u/deon.korb)\
**Post date:** [September 10, 2022, 4:07pm UTC](https://forum.inductiveautomation.com/t/navigation-script-not-executing-ideas/63940/6 "2022-09-10T16:07:08Z")

</div>

Also, writing to a tag, waiting a bit and hope something happens during the sleep time, reading something back and acting on that seems a bit fragile.

I would separate the tag write and the rest of the script. Maybe a change script on bound custom property?

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [September 10, 2022, 6:28pm UTC](https://forum.inductiveautomation.com/t/navigation-script-not-executing-ideas/63940/7 "2022-09-10T18:28:59Z")

</div>

Okay, so here’s a list of the problems identified so far:

1. `meta.visible` expects a boolean `True` /`False` instead of string `"true"` /`"false"` .
2. `system.tag.readBlocking` EXPECTS a list of tagPaths and RETURNS a list of values from those tagPaths.
3. `system.tag.writeBlocking` likewise expects a list of tagPaths and a list of values.

Changes to make:

```auto
system.tag.writeBlocking(['[default]ABS Concentrate System/Barcode_Scanner/_'+str(scanner_id)+'_/Machine_ID'], [wand_num])

```

```auto
status_word = system.tag.readBlocking(['[default]ABS Concentrate System/Barcode_Scanner/_'+str(scanner_id)+'_/Status_Word'])[0].value. # [0] to get the 0th index returned QualifiedValue, and .value to obtain the value of the QV

```

```auto
self.getSibling("Label_1").meta.visible = True

```

```auto
self.getSibling("BadMachine").meta.visible = True

```

```auto
self.getSibling("Label_1").meta.visible = False

```

The `system.tag.writeBlocking` line is almost certainly where your code is failing, but you should have seen logging in the Gateway that this code was failing on that line.

---

<div class="post-metadata">

**Author:** ![thecesrom.git](https://avatars.discourse-cdn.com/v4/letter/t/dfb087/32.png) [@thecesrom.git](https://forum.inductiveautomation.com/u/thecesrom.git)\
**Post date:** [September 10, 2022, 9:30pm UTC](https://forum.inductiveautomation.com/t/navigation-script-not-executing-ideas/63940/8 "2022-09-10T21:30:04Z")

</div>

I was under the same impression, that `system.tag.[read|write]Blocking` expected a list of tagPaths, but in reality it does work if you pass a string. I was shocked when I saw it, but an Integrator did that very same thing all over one project and it was working.

Also `time.sleep()` might break in some cases where the computer’s Locale is not English, I’d recommend using `java.lang.Thread.sleep()` instead.

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [September 10, 2022, 11:52pm UTC](https://forum.inductiveautomation.com/t/navigation-script-not-executing-ideas/63940/9 "2022-09-10T23:52:31Z")

</div>

> [@thecesrom.git](#):
>
> `time.sleep()` might break in some cases where the computer’s Locale is not English

Interesting information

---

<div class="post-metadata">

**Author:** ![thecesrom.git](https://avatars.discourse-cdn.com/v4/letter/t/dfb087/32.png) [@thecesrom.git](https://forum.inductiveautomation.com/u/thecesrom.git)\
**Post date:** [September 11, 2022, 12:08am UTC](https://forum.inductiveautomation.com/t/navigation-script-not-executing-ideas/63940/10 "2022-09-11T00:08:00Z")

</div>

See here.

> [@Importing time module bug](https://forum.inductiveautomation.com/t/importing-time-module-bug/33906):
>
> I wanted to post this here because I would like to check if anyone else is having this same issue within the community. A couple of days ago a user reported they were getting a “cryptic” error that read “Cannot create PyString with non-byte value”. At first I could not replicate the error on my computer, so after doing some remote assistance I finally found the issue, and it relied on a harmless line of code; an import of the time module. The only way I was able to replicate this behavior on …

Not sure if it was fixed in Jython 2.7.2, but why risk it when `java.lang.Thread.sleep()` does what I wanted.

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [September 11, 2022, 6:41am UTC](https://forum.inductiveautomation.com/t/navigation-script-not-executing-ideas/63940/11 "2022-09-11T06:41:21Z")

</div>

> [@cmallonee](#):
>
> - `system.tag.readBlocking` EXPECTS a list of tagPaths and RETURNS a list of values from those tagPaths.
> - `system.tag.writeBlocking` likewise expects a list of tagPaths and a list of values.

These are incorrect. A single tag path and value work as well outside of a list. In earlier versions of 8 they didn't, but a feature request added this back in to mimick the v7 function. However the return is still an array of qualifiedValues

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [September 11, 2022, 3:17pm UTC](https://forum.inductiveautomation.com/t/navigation-script-not-executing-ideas/63940/12 "2022-09-11T15:17:56Z")

</div>

Hmmm. The docs would suggest otherwise. I’ll talk to the Docs team to get them updated.

---

<div class="post-metadata">

**Author:** ![mjohnson0238](https://avatars.discourse-cdn.com/v4/letter/m/4bbf92/32.png) [@mjohnson0238](https://forum.inductiveautomation.com/u/mjohnson0238)\
**Post date:** [September 12, 2022, 1:01pm UTC](https://forum.inductiveautomation.com/t/navigation-script-not-executing-ideas/63940/13 "2022-09-12T13:01:49Z")

</div>

Thanks alot guys! lots of great suggestions. I totally forgot that the readBlocking does in fact return an array. after fixing that issue, it navigated liked it should have. thanks again for help.

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [September 13, 2022, 12:26am UTC](https://forum.inductiveautomation.com/t/navigation-script-not-executing-ideas/63940/14 "2022-09-13T00:26:12Z")

</div>

For future reference, it’s also super handy especially for Perspective, to add try/except blocks around your code to capture and report any errors to the operators. Make sure you have two excepts, one to catch `java.lang.Throwable` errors and the other a catch all (which doesn’t catch java).

E.g.

```auto
from java.lang import Throwable
try:
	# do stuff
except Throwable:
	shared.perspective.errors.displayError()
except:
	shared.perspective.errors.displayError()

```

I use a shared library function to display an error to keep it in one spot. For simplicity’s sake, you could just write the error to the console:

```auto
def displayError():
	import traceback
	system.perspective.print(traceback.format_exc())

```

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [September 13, 2022, 1:31am UTC](https://forum.inductiveautomation.com/t/navigation-script-not-executing-ideas/63940/15 "2022-09-13T01:31:29Z")

</div>

> [@nminchin](#):
>
> but a feature request added this back in to mimick the v7 function. However the return is still an array of qualifiedValues

@thecesrom.git , @nminchin :  
After speaking with the Dev behind the change here, we don't officially support single tag paths - allowing for only a single tag path (and value) was only added to resolve some other issue. The documentation is the supported usage, and so you should always be wrapping your tag paths and values as lists.

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [September 13, 2022, 1:34am UTC](https://forum.inductiveautomation.com/t/navigation-script-not-executing-ideas/63940/16 "2022-09-13T01:34:27Z")

</div>

Hmm, bummer… will do from now on, but there are lots of places I haven’t! (and not because I’m being dumb and reading single tags when I should be reading multiple together, just to clarify 🙂 )
