# Tag Change script trouble shooting

**URL:** <https://forum.inductiveautomation.com/t/tag-change-script-trouble-shooting/8422>\
**Category:** Ignition\
**Created:** [May 7, 2014, 5:13pm UTC](https://forum.inductiveautomation.com/t/tag-change-script-trouble-shooting/8422 "2014-05-07T17:13:35Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ashish007pict](https://avatars.discourse-cdn.com/v4/letter/a/aca169/32.png) [@ashish007pict](https://forum.inductiveautomation.com/u/ashish007pict)\
**Post date:** [May 7, 2014, 5:13pm UTC](https://forum.inductiveautomation.com/t/tag-change-script-trouble-shooting/8422/1 "2014-05-07T17:13:35Z")

</div>

Hello all

I am using Tag Change scripts on my ignition client to store some real time values from PLC to SQL database.  
Earlier I used to get proper data log to SQL. But I don’t know what went wrong and suddenly it stopped. Although I checked manually to insert data in SQL database and its working.  
I wanted to log data only when my tag bit is HIGH.  
Below is my script.  
import system  
import app

SQLtrigger = system.get.tagValue(xxxx)

If SQLtrigger == 1:  
app.datalog.sqlupload()

Above function in if statement works fine if I call it on button event.

Can anyone help me with this?

Thanks  
Ashish

---

<div class="post-metadata">

**Author:** ![diat150](https://avatars.discourse-cdn.com/v4/letter/d/a587f6/32.png) [@diat150](https://forum.inductiveautomation.com/u/diat150)\
**Post date:** [May 7, 2014, 5:28pm UTC](https://forum.inductiveautomation.com/t/tag-change-script-trouble-shooting/8422/2 "2014-05-07T17:28:42Z")

</div>

is this in a client or gateway tag change?

id add some print statements.

some thing like this:

```auto
import system
import app
print 'start script'
SQLtrigger = system.get.tagValue(xxxx)
print SQLtrigger

If SQLtrigger == 1:
    print 'trigger = 1 send to app'
    app.datalog.sqlupload()
    print 'sent to app'
else:
    print 'trigger = 0 do nothing'
```

---

<div class="post-metadata">

**Author:** ![d.laquidain](https://avatars.discourse-cdn.com/v4/letter/d/90ced4/32.png) [@d.laquidain](https://forum.inductiveautomation.com/u/d.laquidain)\
**Post date:** [May 7, 2014, 6:22pm UTC](https://forum.inductiveautomation.com/t/tag-change-script-trouble-shooting/8422/3 "2014-05-07T18:22:45Z")

</div>

Hello,

try it:

import system  
import app

SQLtrigger = system.tag.getTagValue(xxxx)

If SQLtrigger == 1:  
app.datalog.sqlupload()

regards

---

<div class="post-metadata">

**Author:** ![ashish007pict](https://avatars.discourse-cdn.com/v4/letter/a/aca169/32.png) [@ashish007pict](https://forum.inductiveautomation.com/u/ashish007pict)\
**Post date:** [May 8, 2014, 2:04am UTC](https://forum.inductiveautomation.com/t/tag-change-script-trouble-shooting/8422/4 "2014-05-08T02:04:42Z")

</div>

Hi  
I am using this script in client tag change menu.

---

<div class="post-metadata">

**Author:** ![greg.simpson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/greg.simpson/32/3135_2.png) [@greg.simpson](https://forum.inductiveautomation.com/u/greg.simpson)\
**Post date:** [May 13, 2014, 6:10pm UTC](https://forum.inductiveautomation.com/t/tag-change-script-trouble-shooting/8422/5 "2014-05-13T18:10:33Z")

</div>

If this is a client tag change script then you should do it like this

`if newValue.value == 1:
    app.datalog.sqlupload()`

---

<div class="post-metadata">

**Author:** ![hazelchr](https://avatars.discourse-cdn.com/v4/letter/h/e9c0ed/32.png) [@hazelchr](https://forum.inductiveautomation.com/u/hazelchr)\
**Post date:** [May 13, 2014, 7:43pm UTC](https://forum.inductiveautomation.com/t/tag-change-script-trouble-shooting/8422/6 "2014-05-13T19:43:41Z")

</div>

What I’ve found helpful when troubleshooting client and gateway scripts is to wrap the whole thing in a try/except loop and then write the error string to a different SQL table if it finds an exception.

Something like:

```auto
try:
     #your code here

except Exception, e:
     sqltxt="INSERT INTO tblEventLog (eventDate, eventDescription, eventLocation) VALUES(GETDATE(),?,?)
     system.db.runPrepUpdate(sqltxt,[str(e),"Some Locating info"],"yourservername")
```

Including str(e) in your upload will give you the error message about what is going wrong. It doesn’t have the exact line it faulted on, but it helps more than anything else. I usually throw in a tag referencing the client name or hostname as well.

---

<div class="post-metadata">

**Author:** ![greg.simpson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/greg.simpson/32/3135_2.png) [@greg.simpson](https://forum.inductiveautomation.com/u/greg.simpson)\
**Post date:** [May 15, 2014, 9:23pm UTC](https://forum.inductiveautomation.com/t/tag-change-script-trouble-shooting/8422/7 "2014-05-15T21:23:35Z")

</div>

If the tag change script is not running you can also look in the gateway console to see if there is an error logged.
