# Call project script from tag change

**URL:** <https://forum.inductiveautomation.com/t/call-project-script-from-tag-change/12086>\
**Category:** Ignition\
**Created:** [August 30, 2016, 8:29pm UTC](https://forum.inductiveautomation.com/t/call-project-script-from-tag-change/12086 "2016-08-30T20:29:01Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![kael.kohlman](https://avatars.discourse-cdn.com/v4/letter/k/848f3c/32.png) [@kael.kohlman](https://forum.inductiveautomation.com/u/kael.kohlman)\
**Post date:** [August 30, 2016, 8:29pm UTC](https://forum.inductiveautomation.com/t/call-project-script-from-tag-change/12086/1 "2016-08-30T20:29:01Z")

</div>

Hi,

I’m trying to create a simple logger for maintenance troubleshooting. Whenever I call from actionPerformed on a button or the scripting console everything works fine, but when I try to tie it to a tag change nothing wants to cooperate.

Am I calling this right or missing a step somewhere? Any help would be greatly appreciated.  
My setup is Ignition 7.8.2, Java 1.8.0\_77, 2012 R2 with a win7 client

Thanks

Project Script (project.testLog):

```auto
def opsLog(label,valueOld,valueNew):
	#Log sep. by day
	logpath = "C:/logs/Top Line/%s.txt" % str(system.date.format(system.date.now(),"yyyy-MM-dd"))
	logtime = system.date.format(system.date.now(),"HH:mm:ss.SSS")
	dashbreak = "\n-----------------------------------------------------------------------------------\n"
	writedata = "\n%s\t%s\tchanged from %s to %s" % (logtime,label,valueOld,valueNew)

	#Redundant create log if none exists, normally handled by autolog.rb
	if not system.file.fileExists(logpath):
		logbegin = str(system.date.format(system.date.now(),"MMM dd, yyyy"))
		filepath = system.file.saveFile(logpath)
		system.file.writeFile(logpath,"\n\n%s" % dashbreak,1)
		system.file.writeFile(logpath,"\nTop Line Log %s" % logbegin,1)
		system.file.writeFile(logpath,"%s\n" % dashbreak,1)
		system.file.writeFile(logpath,"\nAll times Central with DST accounted for\n\n\n",1)

	system.file.writeFile(logpath,writedata,1) 
```

Gateway console output:  
[attachment=1]Ignconsole.PNG[/attachment]

Call at tag change:  
[attachment=0]TagCall.PNG[/attachment]

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [August 30, 2016, 8:52pm UTC](https://forum.inductiveautomation.com/t/call-project-script-from-tag-change/12086/2 "2016-08-30T20:52:03Z")

</div>

Hi! Welcome to the forums. 🙂

Tag scripts are run in the gateway, while project scripts are run in the client. Two different scopes. A deeper meaning is that the gateway has no idea which project a script is in when you try to call it.

Using a Client Event Script of a Tag Change variety should help you.

---

<div class="post-metadata">

**Author:** ![giulianacaula](https://avatars.discourse-cdn.com/v4/letter/g/779978/32.png) [@giulianacaula](https://forum.inductiveautomation.com/u/giulianacaula)\
**Post date:** [November 22, 2017, 1:41pm UTC](https://forum.inductiveautomation.com/t/call-project-script-from-tag-change/12086/3 "2017-11-22T13:41:28Z")

</div>

Hello,

I have the same error, and by putting the script in the Client Event Script of a Tag Change variety it start to work perfectly.  
The thing is that I want the script to run always, even if the client is not open.

Calling the script from the Client Event Script would only run the script when the client is open, is that correct?

---

<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:** [November 22, 2017, 2:03pm UTC](https://forum.inductiveautomation.com/t/call-project-script-from-tag-change/12086/4 "2017-11-22T14:03:55Z")

</div>

You want to use a project-scope gateway tag change event script, not a tag event. See the description of contexts [here](http://forum.inductiveautomation.com/t/write-to-client-memory-tag-fails-in-tag-event-yet-succeeds-in-client-timer-event/16048/4?u=pturmel).

---

<div class="post-metadata">

**Author:** ![giulianacaula](https://avatars.discourse-cdn.com/v4/letter/g/779978/32.png) [@giulianacaula](https://forum.inductiveautomation.com/u/giulianacaula)\
**Post date:** [November 22, 2017, 2:22pm UTC](https://forum.inductiveautomation.com/t/call-project-script-from-tag-change/12086/5 "2017-11-22T14:22:47Z")

</div>

Yes, I was doing that but it keeps trowing me an error: “Cannot create PyString from null!” and when I put the same in the Tag Change of a Client Event Script

Would the project should be in the global script library (shared)? I didn’t try that yet. I’ll do it right away

---

<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:** [November 22, 2017, 3:00pm UTC](https://forum.inductiveautomation.com/t/call-project-script-from-tag-change/12086/6 "2017-11-22T15:00:02Z")

</div>

> [@giulianacaula](#):
>
> Cannot create PyString from null!

That sounds like a different problem. Note that scripts for [tag events](https://docs.inductiveautomation.com/display/DOC79/Tag+Event+Scripts) are like a custom component methods -- event details are supplied as arguments to the function, and those arguments are locals in that function scope. A [tag change script](https://docs.inductiveautomation.com/display/DOC79/Tag+Change+Scripts) _isn't_ a function -- its details are supplied in an `event` object. You can't just take code from one and paste it in the other.

---

<div class="post-metadata">

**Author:** ![giulianacaula](https://avatars.discourse-cdn.com/v4/letter/g/779978/32.png) [@giulianacaula](https://forum.inductiveautomation.com/u/giulianacaula)\
**Post date:** [November 22, 2017, 3:38pm UTC](https://forum.inductiveautomation.com/t/call-project-script-from-tag-change/12086/7 "2017-11-22T15:38:26Z")

</div>

I am not using a tag event.  
Maybe I’m not making myself clear, or maybe I’m not understanding.

Here I go again.  
I have a script in Ignition’s Shared Script Module (global library) very simple, only inserts some records in a database.  
I want to run this script in 3 specific times of a day (once per shift). So I’ve made a boolean expression tag and What I want is that when that tag’s value is = 1, run the global script.  
I want that script to be run everytime, no matter if the client is open or not. The script should run every time the tag is = 1.

So what I do is create in the project’s gateway event script --\> tag change script, a new tag change script that evaluates the value of my expression tag, and when is = 1, call the global script like this: shared.myScript.testScript()

This is what I do that throws me the “Cannot create PyString from null!” error in the logs.

---

<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:** [November 22, 2017, 4:19pm UTC](https://forum.inductiveautomation.com/t/call-project-script-from-tag-change/12086/8 "2017-11-22T16:19:41Z")

</div>

You’ll have to show your code. We can’t read minds. (At least, _ **I** _ can’t.) Please use a triple-` on the lines before and after your code so it’ll format nicely (readably).

---

<div class="post-metadata">

**Author:** ![giulianacaula](https://avatars.discourse-cdn.com/v4/letter/g/779978/32.png) [@giulianacaula](https://forum.inductiveautomation.com/u/giulianacaula)\
**Post date:** [November 22, 2017, 6:21pm UTC](https://forum.inductiveautomation.com/t/call-project-script-from-tag-change/12086/9 "2017-11-22T18:21:01Z")

</div>

I already make it work !!!

The problem was that for some reason the tags “currentDataTime” and “username” weren’t working.

Thanks!!
