# How to trigger a component script from Perspective page startup

**URL:** <https://forum.inductiveautomation.com/t/how-to-trigger-a-component-script-from-perspective-page-startup/75966>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [July 5, 2023, 9:11pm UTC](https://forum.inductiveautomation.com/t/how-to-trigger-a-component-script-from-perspective-page-startup/75966 "2023-07-05T21:11:50Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![rahman.tarek](https://avatars.discourse-cdn.com/v4/letter/r/b77776/32.png) [@rahman.tarek](https://forum.inductiveautomation.com/u/rahman.tarek)\
**Post date:** [July 5, 2023, 9:11pm UTC](https://forum.inductiveautomation.com/t/how-to-trigger-a-component-script-from-perspective-page-startup/75966/1 "2023-07-05T21:11:50Z")

</div>

Hello,

I have a use case where i have a script running on the button's action Performed event as you can see below

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/a/1a5863b1828163c0b985967d7159ddb7a9f63aab.png)

I want to trigger this script the moment the window is opened. I imagine it has to be a script on the 'Onstartup' system event  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/9/b9fb98edcfce4b4ca52d016c14d5c09146f191e3.png)

But how do i access the function from here? thanks in advance

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [July 5, 2023, 9:15pm UTC](https://forum.inductiveautomation.com/t/how-to-trigger-a-component-script-from-perspective-page-startup/75966/2 "2023-07-05T21:15:37Z")

</div>

You don't; that action will only be executed when the corresponding Event (in this case a click event of the Button while it is enabled) occurs.

If you need to perform the same logic on both Component start-up and in the event of a click, then you should move the logic into a Project Script, and both Events should then execute the Project Script.

---

<div class="post-metadata">

**Author:** ![Usman\_Ashraf](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/usman_ashraf/32/43168_2.png) [@Usman\_Ashraf](https://forum.inductiveautomation.com/u/Usman_Ashraf)\
**Post date:** [July 5, 2023, 9:32pm UTC](https://forum.inductiveautomation.com/t/how-to-trigger-a-component-script-from-perspective-page-startup/75966/3 "2023-07-05T21:32:27Z")

</div>

There is also a difference that you might want to keep in mind. One is a session startup and the other is the page startup. So the button onStartup script will trigger when the session starts and session ID is assigned. This will be the case when the page is opened for the first time or after session expiry time. Once opened, then any subsequent page refreshes will not trigger the button startup script.

If that is the need then please use Project \> Session Events \> Page Startup script area. This will result in the script to be executed even when the page is refreshed.

---

<div class="post-metadata">

**Author:** ![rahman.tarek](https://avatars.discourse-cdn.com/v4/letter/r/b77776/32.png) [@rahman.tarek](https://forum.inductiveautomation.com/u/rahman.tarek)\
**Post date:** [July 5, 2023, 9:57pm UTC](https://forum.inductiveautomation.com/t/how-to-trigger-a-component-script-from-perspective-page-startup/75966/4 "2023-07-05T21:57:41Z")

</div>

you mean this?

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/c/acae0a783a9cc365675f043f8f683c203520ea4b.png)

But how can i access the components of my view from here?

---

<div class="post-metadata">

**Author:** ![nicholas.robinson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nicholas.robinson/32/22188_2.png) [@nicholas.robinson](https://forum.inductiveautomation.com/u/nicholas.robinson)\
**Post date:** [July 6, 2023, 1:17am UTC](https://forum.inductiveautomation.com/t/how-to-trigger-a-component-script-from-perspective-page-startup/75966/5 "2023-07-06T01:17:46Z")

</div>

@rahman.tarek if you have something in your view that you want to be accessible from many places within that view, one thing you can do is create a Boolean custom parameter with a change script that activates it, something like this:

```auto
def valueChanged(self, previousValue, currentValue, origin, missedEvents):
	if currentValue.value:
		logger = system.util.getLogger("loggerName")
		try:
			# do the action here
			self.custom.result = test.add(
				self.custom.num1, 
				self.custom.num2
			)
		except Exception as e:
			logger.error(str(e))
			
		# always set self back to false
		self.custom.doSomething = False

```

I would never have any major script defined there, but rather use it as a convenient way to call it from several different places as needed. To activate it all you have to do is write that value to True.

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/1/e1e21a4628547193f9cd738df617800b0766ae7b.png)

Rgds,

Nick

---

<div class="post-metadata">

**Author:** ![ryan.white](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan.white/32/73193_2.png) [@ryan.white](https://forum.inductiveautomation.com/u/ryan.white)\
**Post date:** [July 6, 2023, 1:37am UTC](https://forum.inductiveautomation.com/t/how-to-trigger-a-component-script-from-perspective-page-startup/75966/6 "2023-07-06T01:37:06Z")

</div>

If you need to call something from multiple locations why not put a script in the project level library and call that? If you need it to be able to put values in a session property then have the script accept the session object as a parameter.

Then all your calls are a single line call to the project level script.

---

<div class="post-metadata">

**Author:** ![rahman.tarek](https://avatars.discourse-cdn.com/v4/letter/r/b77776/32.png) [@rahman.tarek](https://forum.inductiveautomation.com/u/rahman.tarek)\
**Post date:** [July 6, 2023, 2:35pm UTC](https://forum.inductiveautomation.com/t/how-to-trigger-a-component-script-from-perspective-page-startup/75966/7 "2023-07-06T14:35:07Z")

</div>

how would i access the custom parameter from the page startup script?

---

<div class="post-metadata">

**Author:** ![nicholas.robinson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nicholas.robinson/32/22188_2.png) [@nicholas.robinson](https://forum.inductiveautomation.com/u/nicholas.robinson)\
**Post date:** [July 6, 2023, 2:57pm UTC](https://forum.inductiveautomation.com/t/how-to-trigger-a-component-script-from-perspective-page-startup/75966/8 "2023-07-06T14:57:31Z")

</div>

@rahman.tarek all you'd have to do in the page startup is this:

```auto
self.custom.doSomething = True

```

Cheers,

Nick

---

<div class="post-metadata">

**Author:** ![rahman.tarek](https://avatars.discourse-cdn.com/v4/letter/r/b77776/32.png) [@rahman.tarek](https://forum.inductiveautomation.com/u/rahman.tarek)\
**Post date:** [July 6, 2023, 8:02pm UTC](https://forum.inductiveautomation.com/t/how-to-trigger-a-component-script-from-perspective-page-startup/75966/9 "2023-07-06T20:02:14Z")

</div>

didnt work unfortunately

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

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

i created a custom parameter for my page and then had my script on the parameter and tried to trigger it from the pagestartup

---

<div class="post-metadata">

**Author:** ![nicholas.robinson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nicholas.robinson/32/22188_2.png) [@nicholas.robinson](https://forum.inductiveautomation.com/u/nicholas.robinson)\
**Post date:** [July 6, 2023, 8:17pm UTC](https://forum.inductiveautomation.com/t/how-to-trigger-a-component-script-from-perspective-page-startup/75966/10 "2023-07-06T20:17:33Z")

</div>

`currentValue` is the full object and will not work. You'll need to use `currentValue.value`

Good thing about that is if you ever need the timestamp you can also do `currentValue.timestamp`

Nick

---

<div class="post-metadata">

**Author:** ![rahman.tarek](https://avatars.discourse-cdn.com/v4/letter/r/b77776/32.png) [@rahman.tarek](https://forum.inductiveautomation.com/u/rahman.tarek)\
**Post date:** [July 6, 2023, 8:58pm UTC](https://forum.inductiveautomation.com/t/how-to-trigger-a-component-script-from-perspective-page-startup/75966/11 "2023-07-06T20:58:13Z")

</div>

yea i noticed but even after i fix it, it does not work. For sure the script is working but it does not execute when the page refreshes

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [July 6, 2023, 9:00pm UTC](https://forum.inductiveautomation.com/t/how-to-trigger-a-component-script-from-perspective-page-startup/75966/12 "2023-07-06T21:00:14Z")

</div>

> [@rahman.tarek](#):
>
> page refreshes

~~A page _refresh_ does not equate to a Page Startup Event. On the backend, the page has already been created and assigned an ID. During a refresh of the page, that ID is not overwritten, and even the View still exists - you just get a forced re-evaluation of any bindings/appearances.~~

~~We call this out in the [Docs](https://docs.inductiveautomation.com/display/DOC81/Perspective+Session+Event+Scripts#PerspectiveSessionEventScripts-PageStartup:~:text=Startup%20and%20Shutdown-,Page%20Startup,-The%20following%20feature), albeit in the navigation context.~~

> **Note:** Navigating to a page configuration in a tab that's already opened (such as using [system.perspective.navigate](https://docs.inductiveautomation.com/display/DOC81/system.perspective.navigate)) will not trigger this event.

Edit: I'm actually not as sure about this now that I look at it a bit closer... It looks like we do have an automated test to verify a browser refresh DOES trigger the event. Perhaps something else is happening here. Have you verified the value in question is being changed to something other than `1` AFTER the original change?

---

<div class="post-metadata">

**Author:** ![nicholas.robinson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nicholas.robinson/32/22188_2.png) [@nicholas.robinson](https://forum.inductiveautomation.com/u/nicholas.robinson)\
**Post date:** [July 7, 2023, 1:48am UTC](https://forum.inductiveautomation.com/t/how-to-trigger-a-component-script-from-perspective-page-startup/75966/13 "2023-07-07T01:48:06Z")

</div>

I think if he uses the page startup event on the view rather than the session events it will help.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/4/1437a43f3855da7640f05afceee16d3bdab04fe9.png)

Nick

---

<div class="post-metadata">

**Author:** ![rahman.tarek](https://avatars.discourse-cdn.com/v4/letter/r/b77776/32.png) [@rahman.tarek](https://forum.inductiveautomation.com/u/rahman.tarek)\
**Post date:** [July 7, 2023, 3:52pm UTC](https://forum.inductiveautomation.com/t/how-to-trigger-a-component-script-from-perspective-page-startup/75966/14 "2023-07-07T15:52:18Z")

</div>

no this does not work either. i guess perspective doesnt really it as easily. on vision you just have script on visionwindowopened and it works

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [July 7, 2023, 4:00pm UTC](https://forum.inductiveautomation.com/t/how-to-trigger-a-component-script-from-perspective-page-startup/75966/15 "2023-07-07T16:00:23Z")

</div>

Could you share all of the code which operates on that `custom.update` property? I still haven't seen any code which changes it to anything other than `1`.

---

<div class="post-metadata">

**Author:** ![rahman.tarek](https://avatars.discourse-cdn.com/v4/letter/r/b77776/32.png) [@rahman.tarek](https://forum.inductiveautomation.com/u/rahman.tarek)\
**Post date:** [July 7, 2023, 4:09pm UTC](https://forum.inductiveautomation.com/t/how-to-trigger-a-component-script-from-perspective-page-startup/75966/16 "2023-07-07T16:09:02Z")

</div>

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/b/8b2f94e7664c63c01adbe01dbcfb58120b3d430e.png)  
this is a snippet of the code. basically depending on the value of the update property i update my pie chart and table slightly differently

---

<div class="post-metadata">

**Author:** ![nicholas.robinson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nicholas.robinson/32/22188_2.png) [@nicholas.robinson](https://forum.inductiveautomation.com/u/nicholas.robinson)\
**Post date:** [July 7, 2023, 4:14pm UTC](https://forum.inductiveautomation.com/t/how-to-trigger-a-component-script-from-perspective-page-startup/75966/17 "2023-07-07T16:14:33Z")

</div>

it absolutely does work, but you probably have something else wrong that you're not yet seeing.

Example:

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

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/8/e8827e6637e906984ee91f5a044c8bacb3e6b5bc.png)

Then open the screen and look at the logs:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/2/a2a5ac2682afa371bc5b0a23e407e667b8f02cfe.png)

Nick

---

<div class="post-metadata">

**Author:** ![rahman.tarek](https://avatars.discourse-cdn.com/v4/letter/r/b77776/32.png) [@rahman.tarek](https://forum.inductiveautomation.com/u/rahman.tarek)\
**Post date:** [July 7, 2023, 4:18pm UTC](https://forum.inductiveautomation.com/t/how-to-trigger-a-component-script-from-perspective-page-startup/75966/18 "2023-07-07T16:18:26Z")

</div>

hmmm interesting. i will have to troubleshoot it. But i do have a follow up question. So really the main use case is i want the script when update is 0 to run periodically - say every 1 min. this then would update my table and piechart with the live values.

Here you can see i have a 'live overview' button which triggers the script on the update custom property. But ofcourse i have to click this. What is the best way to ensure that the script on the update property when the value equals to 0 runs periodically at a fixed rate of 1 min?

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

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [July 7, 2023, 4:36pm UTC](https://forum.inductiveautomation.com/t/how-to-trigger-a-component-script-from-perspective-page-startup/75966/19 "2023-07-07T16:36:55Z")

</div>

I think there are multiple disconnects going on within this thread.

1. Your use of a Page Startup script is going to result in the update request being sent every time a user opens a new tab for their session.
2. The code you supplied show you using a Page Startup script to set `self.custom.update` to a value of `1`, but the Page Startup script has no concept of `self` - only `page`. I suspect this code is failing to complete and logging errors on your Gateway.
3. @nicholas.robinson appears to be using a View onStartup Event instead of the Page Startup Event.
4. I still see no code which ever sets the `custom.update` property to anything other than `1`. As a result - even if the Page Startup Event succeeds in writing a `1` to the prop - subsequent attempts will not trigger the update because they will be setting the property to have a value it already has, and so the change script will not execute.

---

<div class="post-metadata">

**Author:** ![rahman.tarek](https://avatars.discourse-cdn.com/v4/letter/r/b77776/32.png) [@rahman.tarek](https://forum.inductiveautomation.com/u/rahman.tarek)\
**Post date:** [July 7, 2023, 4:41pm UTC](https://forum.inductiveautomation.com/t/how-to-trigger-a-component-script-from-perspective-page-startup/75966/20 "2023-07-07T16:41:50Z")

</div>

1. That makes sense. And yes i did get errors

2. you can see in the screenshot above i set the update propery to 0 when the user clicks the live overview button

[Next page](https://forum.inductiveautomation.com/t/how-to-trigger-a-component-script-from-perspective-page-startup/75966.md?page=2)
