# Script working in console but not on component events

**URL:** <https://forum.inductiveautomation.com/t/script-working-in-console-but-not-on-component-events/56708>\
**Category:** Ignition\
**Tags:** perspective, ignition81\
**Created:** [March 2, 2022, 11:26am UTC](https://forum.inductiveautomation.com/t/script-working-in-console-but-not-on-component-events/56708 "2022-03-02T11:26:59Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sourabh\_Ambildhuke](https://avatars.discourse-cdn.com/v4/letter/s/f1d935/32.png) [@Sourabh\_Ambildhuke](https://forum.inductiveautomation.com/u/Sourabh_Ambildhuke)\
**Post date:** [March 2, 2022, 11:26am UTC](https://forum.inductiveautomation.com/t/script-working-in-console-but-not-on-component-events/56708/1 "2022-03-02T11:26:59Z")

</div>

Hey,

I am writing one script to open network drive folder on the button action performed.  
I have done all the Mapping required to fetch the drive and script is working in script console but the same is not working either on component event or in gateway script. below is the script attached

import os, fnmatch  
path = “\\gnpunnas\Temporary\”  
files = fnmatch.filter(os.listdir(path), “\*.pdf”)  
print files

---

<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:** [March 2, 2022, 11:31am UTC](https://forum.inductiveautomation.com/t/script-working-in-console-but-not-on-component-events/56708/2 "2022-03-02T11:31:09Z")

</div>

In perspective, all scripts run on the gateway.

The most likely reason is that your gateway does not have permissions to read the directory.

EDIT: That would be the username the gateway service runs under.

---

<div class="post-metadata">

**Author:** ![Sourabh\_Ambildhuke](https://avatars.discourse-cdn.com/v4/letter/s/f1d935/32.png) [@Sourabh\_Ambildhuke](https://forum.inductiveautomation.com/u/Sourabh_Ambildhuke)\
**Post date:** [March 2, 2022, 11:33am UTC](https://forum.inductiveautomation.com/t/script-working-in-console-but-not-on-component-events/56708/3 "2022-03-02T11:33:35Z")

</div>

I have changed the log on properties in services section to change as this account but still it didnt work. is there any specific thing i need to do after that.

---

<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:** [March 2, 2022, 11:35am UTC](https://forum.inductiveautomation.com/t/script-working-in-console-but-not-on-component-events/56708/4 "2022-03-02T11:35:23Z")

</div>

Is there an error that is thrown?

---

<div class="post-metadata">

**Author:** ![Sourabh\_Ambildhuke](https://avatars.discourse-cdn.com/v4/letter/s/f1d935/32.png) [@Sourabh\_Ambildhuke](https://forum.inductiveautomation.com/u/Sourabh_Ambildhuke)\
**Post date:** [March 2, 2022, 11:45am UTC](https://forum.inductiveautomation.com/t/script-working-in-console-but-not-on-component-events/56708/5 "2022-03-02T11:45:33Z")

</div>

INFO | jvm 1 | 2022/03/02 11:42:00 | 1  
INFO | jvm 1 | 2022/03/02 11:42:00 | 0  
INFO | jvm 1 | 2022/03/02 11:42:00 | [default]read  
DEBUG | wrapperp | 2022/03/02 11:42:01 | Send a packet PING : ping 00029969  
INFO | jvm 1 | 2022/03/02 11:42:01 | WrapperManager Debug: Received a packet PING : ping 00029969  
INFO | jvm 1 | 2022/03/02 11:42:01 | WrapperManager Debug: Send a packet PING : ping 00029969  
INFO | jvm 1 | 2022/03/02 11:42:01 | E [TagChangeScriptExecutor] [11:42:01]: Error executing tag change script: perspective\_test/New Script  
INFO | jvm 1 | 2022/03/02 11:42:01 | com.inductiveautomation.ignition.common.script.JythonExecException: Traceback (most recent call last):  
INFO | jvm 1 | 2022/03/02 11:42:01 | File “\<TagChangeScript:perspective\_test/New Script\>”, line 8, in   
INFO | jvm 1 | 2022/03/02 11:42:01 | OSError: (20, ‘Not a directory’, ‘\\gnpunnas1b\Temporary\’)

This is the error i found on wrapper.log file in c drive.

---

<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:** [March 2, 2022, 12:08pm UTC](https://forum.inductiveautomation.com/t/script-working-in-console-but-not-on-component-events/56708/6 "2022-03-02T12:08:58Z")

</div>

- Did you restart the service after changing the account?
- Does it work with a local directory?

---

<div class="post-metadata">

**Author:** ![Sourabh\_Ambildhuke](https://avatars.discourse-cdn.com/v4/letter/s/f1d935/32.png) [@Sourabh\_Ambildhuke](https://forum.inductiveautomation.com/u/Sourabh_Ambildhuke)\
**Post date:** [March 2, 2022, 1:12pm UTC](https://forum.inductiveautomation.com/t/script-working-in-console-but-not-on-component-events/56708/7 "2022-03-02T13:12:12Z")

</div>

1- yes i stopped the service and then started  
2- right now i checked and it is working for local directory

---

<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:** [March 2, 2022, 1:40pm UTC](https://forum.inductiveautomation.com/t/script-working-in-console-but-not-on-component-events/56708/8 "2022-03-02T13:40:19Z")

</div>

Others may chime in, but since it appears you are using a network share, it still seems a permissions issue.

Other things to try:

- Use forward slashes instead of backslashes-- might not be likely to help in this case, as it works locally, but in python, backslashes are used to escape characters. Forward slashes avoids that issue.
- map the share to a drive letter, then update the path.

---

<div class="post-metadata">

**Author:** ![Sourabh\_Ambildhuke](https://avatars.discourse-cdn.com/v4/letter/s/f1d935/32.png) [@Sourabh\_Ambildhuke](https://forum.inductiveautomation.com/u/Sourabh_Ambildhuke)\
**Post date:** [March 2, 2022, 2:21pm UTC](https://forum.inductiveautomation.com/t/script-working-in-console-but-not-on-component-events/56708/9 "2022-03-02T14:21:21Z")

</div>

Thanks @JordanCClark .

My points on network share is that, in perspective i need to open pdf and show it on pdf viewer without using webdev module. any possibilities on this

stuck from long time and didnt get any success.

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [March 2, 2022, 2:23pm UTC](https://forum.inductiveautomation.com/t/script-working-in-console-but-not-on-component-events/56708/10 "2022-03-02T14:23:54Z")

</div>

I don’t think there’s a way around having to fetch the PDF from an url endpoint.

However there are many free python servers you could set up if you don’t want to have to buy the web dev module (though now you have two systems / code bases to maintain, likely in two different versions of python, this is the cost you pay instead of the cost of the web dev module). Flask or Django are the two most popular ones.

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [March 2, 2022, 2:46pm UTC](https://forum.inductiveautomation.com/t/script-working-in-console-but-not-on-component-events/56708/11 "2022-03-02T14:46:50Z")

</div>

i can display pdfs in an iframe from the webapps path.  
`C:\Program Files\Inductive Automation\Ignition\webserver\webapps\main`  
Maybe putting a symlink in there… but ive no idea if that is will work withough the other permissions.  
there are documents about sharing/mappings. ive never read them tho  
[https://docs.inductiveautomation.com/display/DOC81/Mapping+a+Network+Drive](https://docs.inductiveautomation.com/display/DOC81/Mapping+a+Network+Drive)

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [March 2, 2022, 3:48pm UTC](https://forum.inductiveautomation.com/t/script-working-in-console-but-not-on-component-events/56708/12 "2022-03-02T15:48:44Z")

</div>

> [@bkarabinchak.psi](#):
>
> Flask or Django are the two most popular ones.

That seems a bit overkill for just a pdf !

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [March 2, 2022, 4:03pm UTC](https://forum.inductiveautomation.com/t/script-working-in-console-but-not-on-component-events/56708/13 "2022-03-02T16:03:26Z")

</div>

Django sure, flask I could see setting it up in under 50 lines of code if that.

FastAPI would probably be even easier.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [March 2, 2022, 4:07pm UTC](https://forum.inductiveautomation.com/t/script-working-in-console-but-not-on-component-events/56708/14 "2022-03-02T16:07:45Z")

</div>

Or [`bottle`](https://bottlepy.org/docs/dev/tutorial.html#static-files), or use a proxy server like `nginx`, or if it’s Windows (and you’re a masochist) you could use IIS, or you could stand up a webserver in X other programming language of choice - there’s literally infinite options here.

Webdev is convenient because it’s attached to your ‘monolith’ Ignition instance already.

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [March 2, 2022, 4:09pm UTC](https://forum.inductiveautomation.com/t/script-working-in-console-but-not-on-component-events/56708/15 "2022-03-02T16:09:10Z")

</div>

Yea. If costs wasn’t an option I would just get Webdev. Obviously that is not always the case which is why I recommended alternatives. It does seem like overkill but you are trying to do a workaround so it will be a bit of work lol.

---

<div class="post-metadata">

**Author:** ![Sourabh\_Ambildhuke](https://avatars.discourse-cdn.com/v4/letter/s/f1d935/32.png) [@Sourabh\_Ambildhuke](https://forum.inductiveautomation.com/u/Sourabh_Ambildhuke)\
**Post date:** [March 2, 2022, 5:55pm UTC](https://forum.inductiveautomation.com/t/script-working-in-console-but-not-on-component-events/56708/16 "2022-03-02T17:55:09Z")

</div>

Thanks @bkarabinchak.psi

So in your opinion is to create API and use it in ignition. As i will update one thing i am getting the link of network drive in tag and i only need to show it on pdf viewer so maybe for that i need to create API or if can i convert the static link into weburl if possible.

---

<div class="post-metadata">

**Author:** ![Sourabh\_Ambildhuke](https://avatars.discourse-cdn.com/v4/letter/s/f1d935/32.png) [@Sourabh\_Ambildhuke](https://forum.inductiveautomation.com/u/Sourabh_Ambildhuke)\
**Post date:** [March 2, 2022, 5:56pm UTC](https://forum.inductiveautomation.com/t/script-working-in-console-but-not-on-component-events/56708/17 "2022-03-02T17:56:04Z")

</div>

Thanks.

So i will try to use this feature and see if i find any success on the same
