# Removing "imports" from event handler scripts

**URL:** <https://forum.inductiveautomation.com/t/removing-imports-from-event-handler-scripts/80873>\
**Category:** Ignition\
**Created:** [October 23, 2023, 6:42pm UTC](https://forum.inductiveautomation.com/t/removing-imports-from-event-handler-scripts/80873 "2023-10-23T18:42:42Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bushmatic](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bushmatic/32/87014_2.png) [@Bushmatic](https://forum.inductiveautomation.com/u/Bushmatic)\
**Post date:** [October 23, 2023, 6:42pm UTC](https://forum.inductiveautomation.com/t/removing-imports-from-event-handler-scripts/80873/1 "2023-10-23T18:42:42Z")

</div>

We have an `'import sys'` statement at the beginning of an event handler script (for propertyChange -- on a property that changes a lot). This is on a "high traffic" screen that drives a lot of our actual manufacturing processes. Since joining this forum I've learned that it is bad practice to do imports on an event handler.

My question is, could I simply add `import sys` (or whatever other module is needed) in a client startup script? After which point I could call the related functions in any script contained in the project?

Side note, I have the same dumb question but for tags too. If we have a tag change script firing every so often that contains an import statement, where can we even move the import statement to? A gateway script?

---

<div class="post-metadata">

**Author:** ![Felipe\_CRM](https://avatars.discourse-cdn.com/v4/letter/f/dfb087/32.png) [@Felipe\_CRM](https://forum.inductiveautomation.com/u/Felipe_CRM)\
**Post date:** [October 23, 2023, 6:45pm UTC](https://forum.inductiveautomation.com/t/removing-imports-from-event-handler-scripts/80873/2 "2023-10-23T18:45:56Z")

</div>

You would refactor the event handler scripts to call functions from a project library script (or as many as needed to stay well-organized) instead. At the top of that project library script, you would put your `import` statements, no client startup script required.

> [@Bushmatic](#):
>
> a tag change script firing every so often that contains an import statement

The same thing would apply here. Put the actual logic in the project library script and then call it from your tag change script. If it's a ~~gateway tag change script, which it probably should be,~~ change script on the tag itself (thanks @JordanCClark), you'd set up your project as the [gateway scripting project](https://docs.inductiveautomation.com/display/DOC81/Project+Library#ProjectLibrary-GatewayScriptingProject) in the gateway Config section.

As a bonus, this should make it easier to update any repeated code as it would only exist in one place.

---

<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:** [October 23, 2023, 6:49pm UTC](https://forum.inductiveautomation.com/t/removing-imports-from-event-handler-scripts/80873/3 "2023-10-23T18:49:33Z")

</div>

> [@Bushmatic](#):
>
> Side note, I have the same dumb question but for tags too. If we have a tag change script firing every so often that contains an import statement, where can we even move the import statement to? A gateway script?

Yes, into the Gateway Scripting Project.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/7/d708f2c18716fb06424d9bd955dce9d89544d050.png)

---

<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:** [October 23, 2023, 6:52pm UTC](https://forum.inductiveautomation.com/t/removing-imports-from-event-handler-scripts/80873/4 "2023-10-23T18:52:27Z")

</div>

> [@Felipe\_CRM](#):
>
> If it's a gateway tag change script,

These can be scoped into the project. Scripts running from the tags themselves need to be scoped to the gateway scripting project.

---

<div class="post-metadata">

**Author:** ![Felipe\_CRM](https://avatars.discourse-cdn.com/v4/letter/f/dfb087/32.png) [@Felipe\_CRM](https://forum.inductiveautomation.com/u/Felipe_CRM)\
**Post date:** [October 23, 2023, 7:00pm UTC](https://forum.inductiveautomation.com/t/removing-imports-from-event-handler-scripts/80873/5 "2023-10-23T19:00:45Z")

</div>

Thanks for that clarification! I got mixed up thinking that it was both tag and gateway change events that were gateway scoped.

---

<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:** [October 23, 2023, 7:30pm UTC](https://forum.inductiveautomation.com/t/removing-imports-from-event-handler-scripts/80873/6 "2023-10-23T19:30:54Z")

</div>

> [@Felipe\_CRM](#):
>
> both tag and gateway change events that were gateway scoped.

They **are** both gateway **scoped**. But only the events on the tag themselves use the Gateway Scripting Project setting.

---

<div class="post-metadata">

**Author:** ![Felipe\_CRM](https://avatars.discourse-cdn.com/v4/letter/f/dfb087/32.png) [@Felipe\_CRM](https://forum.inductiveautomation.com/u/Felipe_CRM)\
**Post date:** [October 23, 2023, 7:43pm UTC](https://forum.inductiveautomation.com/t/removing-imports-from-event-handler-scripts/80873/7 "2023-10-23T19:43:04Z")

</div>

That makes sense, since the tags don't belong to any specific project.

---

<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:** [October 23, 2023, 8:07pm UTC](https://forum.inductiveautomation.com/t/removing-imports-from-event-handler-scripts/80873/8 "2023-10-23T20:07:06Z")

</div>

Yeah, scoped was the wrong word to use. Reference would probably have been closer.

We had our grandson over the weekend, and I'm still recovering. 🤪
