# Executing script based on button

**URL:** <https://forum.inductiveautomation.com/t/executing-script-based-on-button/43570>\
**Category:** Ignition\
**Tags:** perspective, scripting\
**Created:** [February 18, 2021, 3:37pm UTC](https://forum.inductiveautomation.com/t/executing-script-based-on-button/43570 "2021-02-18T15:37:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![michael.black](https://avatars.discourse-cdn.com/v4/letter/m/ee7513/32.png) [@michael.black](https://forum.inductiveautomation.com/u/michael.black)\
**Post date:** [February 18, 2021, 3:37pm UTC](https://forum.inductiveautomation.com/t/executing-script-based-on-button/43570/1 "2021-02-18T15:37:47Z")

</div>

I have a button on a popup screen I am executing a script on. I have put the script in the Scripting folder.  
I have created a function called parts\_in\_entry. I am also passing in a parameter from the popup screen (view) called CellId. I have tried numerous things and my script does not seem to work in the scripting folder. Also I have tried the print function to get something to work on the output console and outside of saving the project none of the ‘print’ commands work.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/0/3003b1a04eb551db394eee072f4f2f8a285fe89b.png)

Here is the script I have in the scripting folder. The script is called EntryControl.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/6/b63e29b0a545deba3faa411f2bb8ba1b78415f88.png)

I had it working, at least the first part of the if statement, when I actually defined the cellid inside of the function and tied it to self.view.params.CellId but thought why not just pass it along as a parameter. I am using wrong formatting?

I also put the print command within the function and still nothing in the output console

---

<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:** [February 18, 2021, 4:29pm UTC](https://forum.inductiveautomation.com/t/executing-script-based-on-button/43570/2 "2021-02-18T16:29:31Z")

</div>

You’ve got some mistakes in your thinking about how things work.  
First, you’re passing a literal string `'{self.view.params.cellId}'` in to your project script. That’s not going to be replaced by anything, or do anything dynamic - it’s just going to be a string when it makes it into your script. Curly brace dynamic value lookups only happen in expressions - not in scripting. If you want to pass just the value of a parameter, then you should use it verbatim: `EntryControl.parts_in_entry(self.view.params.cellId)`  
However, that will bring you to your next problem; on line 13 of your EntryControl script you’re calling `self.getSibling` - but what is `self`? Since you’ve jumped into a project script, you no longer have the explicit parameters you have in the `runAction` block. If you want to reference `self` or `event` in your project script, you must explicitly pass them along (or, in this case, better style - just pass the value you want to read as well).

---

<div class="post-metadata">

**Author:** ![michael.black](https://avatars.discourse-cdn.com/v4/letter/m/ee7513/32.png) [@michael.black](https://forum.inductiveautomation.com/u/michael.black)\
**Post date:** [February 18, 2021, 9:13pm UTC](https://forum.inductiveautomation.com/t/executing-script-based-on-button/43570/3 "2021-02-18T21:13:40Z")

</div>

Thanks! Makes sense and was able to get it working.  
Just like I can pass in self or event properties into the project script, can I also pass out or change self properties from the script?

---

<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:** [February 18, 2021, 10:10pm UTC](https://forum.inductiveautomation.com/t/executing-script-based-on-button/43570/4 "2021-02-18T22:10:58Z")

</div>

Yes, you can - just that it (can be) confusing to reason about things if you pass variables around, especially since you can rename them with every layer of indirection.

---

<div class="post-metadata">

**Author:** ![michael.black](https://avatars.discourse-cdn.com/v4/letter/m/ee7513/32.png) [@michael.black](https://forum.inductiveautomation.com/u/michael.black)\
**Post date:** [February 19, 2021, 3:10pm UTC](https://forum.inductiveautomation.com/t/executing-script-based-on-button/43570/5 "2021-02-19T15:10:55Z")

</div>

Right. Good to know, thanks.
