# Troubleshooting Tag Event scripts

**URL:** <https://forum.inductiveautomation.com/t/troubleshooting-tag-event-scripts/8763>\
**Category:** Ignition\
**Created:** [July 21, 2014, 6:40pm UTC](https://forum.inductiveautomation.com/t/troubleshooting-tag-event-scripts/8763 "2014-07-21T18:40:15Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![WildeKurt](https://avatars.discourse-cdn.com/v4/letter/w/50afbb/32.png) [@WildeKurt](https://forum.inductiveautomation.com/u/WildeKurt)\
**Post date:** [July 21, 2014, 6:40pm UTC](https://forum.inductiveautomation.com/t/troubleshooting-tag-event-scripts/8763/1 "2014-07-21T18:40:15Z")

</div>

I’ve run into some occasions where something I’ve done is causing an Event Script to error out (I know this from the little red x that appears next to the tag in the browser). However, no error information goes to the console. What’s the best way of getting more information in these situations?

---

<div class="post-metadata">

**Author:** ![WildeKurt](https://avatars.discourse-cdn.com/v4/letter/w/50afbb/32.png) [@WildeKurt](https://forum.inductiveautomation.com/u/WildeKurt)\
**Post date:** [July 21, 2014, 9:01pm UTC](https://forum.inductiveautomation.com/t/troubleshooting-tag-event-scripts/8763/2 "2014-07-21T21:01:33Z")

</div>

More questions regarding Tag Events: I seem to be having difficulty calling other routines from inside a routine called by a tag event. This same script works when it’s called from the script playground but fails when calling it from a Tag Event. For example:

import shared

if shared.util.serialExists(serialNumber) == True :  
do something

I’ve also tried import shared.util with no difference.

---

<div class="post-metadata">

**Author:** ![nmudge](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nmudge/32/3394_2.png) [@nmudge](https://forum.inductiveautomation.com/u/nmudge)\
**Post date:** [July 21, 2014, 10:51pm UTC](https://forum.inductiveautomation.com/t/troubleshooting-tag-event-scripts/8763/3 "2014-07-21T22:51:20Z")

</div>

Don’t import shared, it is already imported. Just call your shared function. For example:

```auto
if shared.util.serialExists(serialNumber) == True :
    do something
```

It seems that importing “shared” in Tag Event Scripts causes these scripts not to work. I get the error, “No module named shared”.

To catch Tag Event Script errors and report them in the console use a logger and try and except. Here is an example:

```auto
import sys
logger = system.util.getLogger("MyLogger")
try:
    if shared.util.serialExists(serialNumber) == True :
        do something
except:
    logger.error(str(sys.exc_info()[1]))    
```

Cheers,

---

<div class="post-metadata">

**Author:** ![WildeKurt](https://avatars.discourse-cdn.com/v4/letter/w/50afbb/32.png) [@WildeKurt](https://forum.inductiveautomation.com/u/WildeKurt)\
**Post date:** [July 22, 2014, 1:49pm UTC](https://forum.inductiveautomation.com/t/troubleshooting-tag-event-scripts/8763/4 "2014-07-22T13:49:08Z")

</div>

I also get an error on any db query’s:

```auto
       import sys
	try:
		sel = "SELECT COUNT(ID) FROM InProcMain WHERE SerialNumber = '" + serialNumber + "'"
		if system.db.runScalarQuery(sel) > 0 :
			return True
		else :
			return False
	except :
		logger = system.util.getLogger("ALogger")
		logger.error(str(sys.exc_info()[1]))		
		return False
```

This get me: `java.lang.Exception: Error executing system.db.runScalarQuery(SELECT COUNT(ID) FROM InProcMain WHERE SerialNumber = '12345', , ) `

The same thing works from the script playground or elsewhere. It doesn’t seem to matter if I use import system or not.

Kurt

---

<div class="post-metadata">

**Author:** ![adamaustin](https://avatars.discourse-cdn.com/v4/letter/a/5f8ce5/32.png) [@adamaustin](https://forum.inductiveautomation.com/u/adamaustin)\
**Post date:** [July 22, 2014, 2:29pm UTC](https://forum.inductiveautomation.com/t/troubleshooting-tag-event-scripts/8763/5 "2014-07-22T14:29:23Z")

</div>

You should show the entire error message. It will tell us why the SQL is incorrect. You should also try pasting all of your code. For example, where is serialNumber defined in the above example code?

---

<div class="post-metadata">

**Author:** ![WildeKurt](https://avatars.discourse-cdn.com/v4/letter/w/50afbb/32.png) [@WildeKurt](https://forum.inductiveautomation.com/u/WildeKurt)\
**Post date:** [July 22, 2014, 2:33pm UTC](https://forum.inductiveautomation.com/t/troubleshooting-tag-event-scripts/8763/6 "2014-07-22T14:33:47Z")

</div>

That is the entire message. The query itself is valid. This only occurs when calling from an tag event.

---

<div class="post-metadata">

**Author:** ![adamaustin](https://avatars.discourse-cdn.com/v4/letter/a/5f8ce5/32.png) [@adamaustin](https://forum.inductiveautomation.com/u/adamaustin)\
**Post date:** [July 22, 2014, 2:50pm UTC](https://forum.inductiveautomation.com/t/troubleshooting-tag-event-scripts/8763/7 "2014-07-22T14:50:39Z")

</div>

Ah, sorry, I forgot this is Ignition 7.7, so I might not be able to help, but you could still try specifying the database name for the query. It might be that Ignition doesn’t know what default database to use (since Tag Events would have a “global” or “shared” scope):

```auto
      if system.db.runScalarQuery(sel, "DataBaseNameYouDefinedInIgnitionWebpage") > 0 :
         return True
      else :
         return False
```

---

<div class="post-metadata">

**Author:** ![nmudge](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nmudge/32/3394_2.png) [@nmudge](https://forum.inductiveautomation.com/u/nmudge)\
**Post date:** [July 22, 2014, 3:10pm UTC](https://forum.inductiveautomation.com/t/troubleshooting-tag-event-scripts/8763/8 "2014-07-22T15:10:12Z")

</div>

Adam, is correct. Tag Event Scripts do not belong to any project so it doesn’t get any project’s default datasource. So you either need to specify the datasource or set a default datasource for the Realtime Tag Provider.

Here is proper exception reporting that will show the exception in the console:

```auto
	logger = system.util.getLogger("MyLogger")
	try:
		sel = "SELECT 10"
		value = system.db.runScalarQuery(sel)
		logger.info("The value is %s"% value)
	except:
		import sys
		from java.lang import Exception
		exceptionType, exception, stack = sys.exc_info()
		if exceptionType == Exception:
			exception = exception.getCause()
		logger.error(exception.getMessage(), exception)
```

Is there a reason you are returning a value from a Tag Event Script? Returning a value from an Event Tag Script doesn’t do anything but return from the function.

---

<div class="post-metadata">

**Author:** ![WildeKurt](https://avatars.discourse-cdn.com/v4/letter/w/50afbb/32.png) [@WildeKurt](https://forum.inductiveautomation.com/u/WildeKurt)\
**Post date:** [July 22, 2014, 4:11pm UTC](https://forum.inductiveautomation.com/t/troubleshooting-tag-event-scripts/8763/9 "2014-07-22T16:11:53Z")

</div>

Specifying a db did the trick. In hindsight it seems obvious. Thanks

---

<div class="post-metadata">

**Author:** ![Colby.Clegg](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/colby.clegg/32/3282_2.png) [@Colby.Clegg](https://forum.inductiveautomation.com/u/Colby.Clegg)\
**Post date:** [July 22, 2014, 5:50pm UTC](https://forum.inductiveautomation.com/t/troubleshooting-tag-event-scripts/8763/10 "2014-07-22T17:50:32Z")

</div>

Hi,

Also, in 7.7.1 we’ll log some sort of message to the console when scripts error out. Currently they log on debug level against the tag provider logger (of the top of my head, I think it’s like “Provider[default]” for the “default” provider).

Regards,

---

<div class="post-metadata">

**Author:** ![nmudge](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nmudge/32/3394_2.png) [@nmudge](https://forum.inductiveautomation.com/u/nmudge)\
**Post date:** [July 23, 2014, 11:59pm UTC](https://forum.inductiveautomation.com/t/troubleshooting-tag-event-scripts/8763/11 "2014-07-23T23:59:13Z")

</div>

When the tag providor log level is changed to debug or higher exceptions are not logged.

I also noticed that exceptions in Tag Event Scripts are not logged to the wrapper.log file.
