The 'onStartup' event script fires multiple times when the project is saved

Hello everyone,

I have a script running in the onStartup event for all the views in a project to save log data.

The issue is that every time I save a view, and a client is currently on that view, the script fires again, causing fake logs to be saved in the database.

How can I prevent this?

Thank you for your help!

You cannot. The startup event is almost never the right event to use for such purposes. Please share what you actually need done.

I understand. I just need to log all the pages that users navigate to.

The script in the onStartup is is as follows:


	# Logger 
	viewName = self.view.id.split('@')[0]
	user = self.session.props.auth.user.userName
	project = system.util.getProjectName()
	timezone = self.session.props.device.timezone.id 
	Generali.Session_Info.userSessionInfo(user=user, project=project, viewName=viewName, timezone=timezone)

The function that is called just insert in the database the data according to my needs.

But that isn't going to catch all of the navigation. That event doesn't catch all returns to a view, so is not fit for your stated purpose. You should be instrumenting the actions where navigation is initiated.

Move this to a project script that will take parameters and then when you click on a navigation button or have an action like @pturmel said to navigate run it there. It will be a simple one-liner someScript.logNavigation or something of the sort.

So for example in my case I should work on the menuTree component where I manage the navigation?

@Benjamin_Furlani I'll make a test, thank you for the help

2 Likes