I have a view that displays table data, and this data is updated frequently from different screens. There are multiple active sessions open that use this same view.
I want all of those sessions to refresh whenever the table data is updated.
Right now, I’m using a message handler on root of the view that refreshes the table by calling the refreshBinding() function.
If you call a gateway message handler, then use it to call the session message handlers, you can call a refresh from any session. This should let you refresh anything you need within the client scope.
Add a Component Message Handler to each component that you would want to refresh, and have them listen for that refresh-components message. have that run some code like self.refreshBinding("props.text") or self.refreshBinding("props.value"), depending on the component & binding you are refreshing
In whatever script that would trigger the components to refresh. So in your case, when the data is updated.
If the data is updated by an external source outside of Ignition, you could use the Webdev module to have a POST request trigger the refresh. Otherwise, you might want to have a query tag refresh at a regular interval and have these table components bind their data that one tag. This will reduce your total amount of queries being executed.
See what errors you might be getting in your gateway's wrapper log. You might be doing something wrong. Also feel free to share (nicely formatted using `) code and someone here could potentially help you...
Might not be ideal or cover all edge cases, but this is what I usually use when having to send a message to all sessions:
def multi_session_send_message(message, payload = {}, scope = "session", projectFilter = []):
"""
Refresh all script accross session
Mandatory when the refresh is needed on multiple device using the workstation app
"""
if len(projectFilter) > 0:
sessions = system.perspective.getSessionInfo(projectFilter = projectFilter)
else:
sessions = system.perspective.getSessionInfo()
for session in sessions:
try:
system.perspective.sendMessage(messageType = message, payload = payload, scope = scope, sessionId = session["id"])
except:
pass
If you want to send a message to all sessions viewing a specific project, make sure to fill in the projectFilter argument (note this is a list of strings).
You can call this function from a button or a script library function or whatever, it works almost the same as system.perspective.sendMessage.
Usually, I keep the scope as session and make sure that the session listen scope is ticked on the message handler I’m targeting.
It appears you have perspective components that update the table data, and you want to tell all other sessions that have that table open, to refresh it. I assume all these sessions would be running the same project?