Message handler behavior

Hi,

I've been pulling my hair out with this one for a while. I'm probably missing something really simple.

I have a view in perspective, which contains a table. The table is populated with data from several different sources, so I have used a script to build the dataset myself.

To update the data in the table I used a message handler script on the table itself. I then tested that the script worked by adding a button which sends a message to the message handler. This works fine and the table data updates from the button.

The main view in the project uses a tab container, with different embedded views within each tab. I wanted to ensure that the table data is up-to-date, automatically when its tab is selected, rather than using a button. To do this, I have a change script on the 'currentTabIndex' property of the tab container. This script sends the same message to the table message handler as the button does.

I have print statements at various points in the script, so I can see that it is definitely running, however, the data shown in the table does not update when the message is received from the property change event. The data in the table will only update off the button.

The message handler scope is set to session. The first few lines of script as follows:

	# set up error logger
	import sys
	import traceback
	logger = system.util.getLogger("update quote table message handler")
	scriptName = "update quote table message handler"
	
	try:
		system.perspective.print("fired from: " + str(payload['source']))
		system.perspective.print("this is the update quote table(table) message script: first line")
		# get external calibrations due soon
		now = system.date.now()
		dueBefore = system.date.format(system.date.addMonths(now, 2),"yyyy-MM-01")
		data = system.db.runNamedQuery("externalQuotes/externalDue",{"dueBefore":dueBefore})
		pyData = system.dataset.toPyDataSet(data)

The button sends this message:

	payload={'source':'update table onClick'}
	system.perspective.sendMessage("updateQuoteTable",payload,scope='session')

The property change sript sends this message:

	payload = {'source':'tabIndexChangeEvent'}
	system.perspective.sendMessage("updateQuoteTable",payload,scope='session')

The only difference being the payload, so i can see where the message was received from.

The console shows that the script is firing from the tab index change event and running to completion:

11:07:38.942 [Browser Thread: a0f567c5-1801-4ebb-9559-c80ffb61fa5c] INFO  Perspective.Designer.Workspace - fired from: tabIndexChangeEvent
11:07:38.942 [Browser Thread: a0f567c5-1801-4ebb-9559-c80ffb61fa5c] INFO  Perspective.Designer.Workspace - this is the update quote table(table) message script: first line
11:07:39.009 [Browser Thread: a0f567c5-1801-4ebb-9559-c80ffb61fa5c] INFO  Perspective.Designer.Workspace - this is the update quote table(table) message script: quotes already sent query ran
11:07:39.009 [Browser Thread: a0f567c5-1801-4ebb-9559-c80ffb61fa5c] INFO  Perspective.Designer.Workspace - this is the update quote table(table) message script: company contact tag read
11:07:39.031 [Browser Thread: a0f567c5-1801-4ebb-9559-c80ffb61fa5c] INFO  Perspective.Designer.Workspace - this is the update quote table(table) message script: dataset updated with supplier emails
11:07:39.031 [Browser Thread: a0f567c5-1801-4ebb-9559-c80ffb61fa5c] INFO  Perspective.Designer.Workspace - this is the update quote table(table) message script: row styling added
11:07:39.031 [Browser Thread: a0f567c5-1801-4ebb-9559-c80ffb61fa5c] INFO  Perspective.Designer.Workspace - this is the update quote table(table) message script: table data updated
11:07:39.032 [Browser Thread: a0f567c5-1801-4ebb-9559-c80ffb61fa5c] INFO  Perspective.Designer.Workspace - this is the update quote table(table) message script: end of script


I thought it might be something to do with not having the focus on the view, so I tried setting the focus in the script as well, but it didn't make a difference.

Sorry it's a long post. I've tried to include as much info as I can. Anyone have any ideas what is going wrong here?

Thanks,
Leigh

Nothing obviously wrong so far.
Can you show where you update the table's data property?

The table data is updated at the end of the message handler script. The script brings data from different sources, adds row style based on cell values and

jsonData = []
backgroundColor = '#30d156'
for row in finalPyData:
	rowDict = {}
	if row['alreadySent'] == 1:
		rowDict['posid'] = {'value': row['posid'], 'style': {'backgroundColor': backgroundColor}}
		rowDict['pos_name'] = {'value': row['pos_name'], 'style': {'backgroundColor': backgroundColor}}
		rowDict['Device_type'] = {'value': row['Device_type'], 'style': {'backgroundColor': backgroundColor}}
		rowDict['serial#'] = {'value': row['serial#'], 'style': {'backgroundColor': backgroundColor}}
		rowDict['model'] = {'value': row['model'], 'style': {'backgroundColor': backgroundColor}}
		rowDict['nextduedate'] = {'value': row['nextduedate'], 'style': {'backgroundColor': backgroundColor}}
		rowDict['lastdoneby'] = {'value': row['lastdoneby'], 'style': {'backgroundColor': backgroundColor}}
		rowDict['certificateno'] = {'value': row['certificateno'], 'style': {'backgroundColor': backgroundColor}}
		rowDict['filename'] = {'value': row['filename'], 'style': {'backgroundColor': backgroundColor}}
		rowDict['sendTo'] = {'value': row['sendTo'], 'style': {'backgroundColor': backgroundColor}}
		rowDict['sendEmail'] = {'value': row['sendEmail'], 'style': {'backgroundColor': backgroundColor}}
		rowDict['alreadySent'] = {'value': row['alreadySent'], 'style': {'backgroundColor': backgroundColor}}
		rowDict['sentDate'] = {'value': row['sentDate'], 'style': {'backgroundColor': backgroundColor}}
		rowDict['sentTo'] = {'value': row['sentTo'], 'style': {'backgroundColor': backgroundColor}}
		rowDict['sentBy'] = {'value': row['sentBy'], 'style': {'backgroundColor': backgroundColor}}
	else:
		rowDict['posid'] = {'value': row['posid']}
		rowDict['pos_name'] = {'value': row['pos_name']}
		rowDict['Device_type'] = {'value': row['Device_type']}
		rowDict['serial#'] = {'value': row['serial#']}
		rowDict['model'] = {'value': row['model']}
		rowDict['nextduedate'] = {'value': row['nextduedate']}
		rowDict['lastdoneby'] = {'value': row['lastdoneby']}
		rowDict['certificateno'] = {'value': row['certificateno']}
		rowDict['filename'] = {'value': row['filename']}
		rowDict['sendTo'] = {'value': row['sendTo']}
		rowDict['sendEmail'] = {'value': row['sendEmail']}
		rowDict['alreadySent'] = {'value': row['alreadySent']}
		rowDict['sentDate'] = {'value': row['sentDate']}
		rowDict['sentTo'] = {'value': row['sentTo']}
		rowDict['sentBy'] = {'value': row['sentBy']}
	jsonData.append(rowDict)
self.props.data = jsonData

Like I say, it's the same message handler being used. Just the source that sends the message which changes. Works fine off the button, but not off the property change event. Even though the print statements show that the script is running.

What does the message handler script look like?

You might be checking something that is making the script behave differently when called from the update script. Add more logging prints at the various checks and actions.

This is an interesting problem... I think it would be difficult to help you troubleshoot unless you included the entire script.

Take this with a grain of salt, but usually when I find weird situations like this, it has to do with a race condition. For instance, variable assignment i.e.

self.props.data = jsonData

happens async, so, for instance, if you then reference self.props.data in the next line of your script, you could likely still be looking at the old data, even though you just assigned jsonData to it, if that makes sense.

1 Like