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.
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.
@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:
def valueChanged(self, previousValue, currentValue, origin, missedEvents):
logger = system.util.getLogger("loggerName")
# do the action here
self.custom.result = test.add(
except Exception as 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.
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.
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, albeit in the navigation context.
Note: Navigating to a page configuration in a tab that's already opened (such as using 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?
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?
I think there are multiple disconnects going on within this thread.
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.
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.
@nicholas.robinson appears to be using a View onStartup Event instead of the Page Startup Event.
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.