Refresh table data in all perspective sessions

Hi,

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.

any idea how to refresh all the sessions?

Thanks!!!

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.

Thanks for your response!!!

How to do this?
I am not sure about gateway message Handler and session message handler.

  1. system.util.sendMessage to send the message to all active sessions.

  2. Create a message handler and have that message handler call
    system.perspective.sendMessage using a message string like refresh-components.

  3. 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

I understood 2nd and 3rd step, but for step 1 I have doubt, where to write system.util.sendMessage?

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.

2 Likes

I am trying but still not working.

This project is inherited; will it cause any issue?

No, inheritance would not be relevant for this.

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.

I tried this approach, but the message is firing dozens of times — around 50 or 60 — and I’m worried it may impact performance.

Here’s what my setup looks like:

  • I have a root-level message handler called RefreshList, which refreshes the table binding.

  • I also created a session-level message handler called RefreshAllSession.

  • Inside the RefreshList handler, I call RefreshAllSession using:

  • system.util.sendMessage(
        project=system.util.getProjectName(),
        messageHandler='RefreshAllSession'
    )
    

RefreshList gets triggered from every component that updates the table, as well as from the RefreshAllSession handler itself. For example:

system.perspective.sendMessage('RefreshList', scope='session')

It’s a bit hard to describe without screenshots, but this is the best way I can explain the behavior.

“Can someone help me understand what I might be doing wrong here?”

I think you're creating a loop.

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?

On the components that perform the table edits:

   system.util.sendMessage(
         project="whatevertheprojectis",
         messageHandler="RefreshTable",
         )

In the project session events, create a message handler "RefreshTable". It needs to send a message further along:

   system.perspective.sendMessage(
          messageType="Refresh",
          payload = {},
          scope="session"
          )      

Now on the table itself (or on the root of the view or wherever you prefer), create a message handler "Refresh".

whatever code you need to refresh the table based on where you put the handler.