configureCell extension function not working

I have a power table where I want to change the background color of the row if the string value of the column “username” equals the user that is currently logged in.

This is the code I can’t get to work:

	currentuser = system.tag.readBlocking("[System]Client/User/Username.Value")
	
	if self.data.getValueAt(rowView, "username") == currentuser:
		return {'background': 'red'}
	else:
		return {'background': 'white'}

I have got the following code to do exactly what I want. If I change currentuser to actual string values it works which makes me think it has something to do with currentuser?

	if self.data.getValueAt(rowView, "username") == "joe":
		return {'background': 'red'}
	elif self.data.getValueAt(rowView, "username") == "mike":
		return {'background': 'yellow'}
	else:
		return {'background': 'white'}
  1. Don’t use readBlocking in a configureCell function, even for client tags. Add a custom property to the power table and bind that property to the client tag. The configureCell function is run directly on the event dispatch thread, so any ‘blocking’ work will lead to significant UI performance degradation - which leads to frustrated users. Client tag reads are relatively safe, because they’re entirely local, but it’s still a bad practice to do anything with tags, the database, etc, in a blocking event handler.
  2. readBlocking returns a list of QualifiedValue objects - you need to unpack that list, and extract the value property (both things that happen automatically if you use a custom property tag binding).

A script to do what you want would be something like this:
currentuser = system.tag.readBlocking("[System]Client/User/Username")[0].value
But, again - use a custom property, and you don’t have to worry about this.

2 Likes

I see. Just did read about not putting a system.tag.readBlock in this function call.

If the power table is called PowerTable and my custom property is called currentuser would I use
self.view.custom.PowerTable.currentuser ?

This is Vision. Custom properties are addressable directly on the component, self.currentuser in this case.

3 Likes

Much appreciated!

Resulting code:

	if self.currentuser == self.data.getValueAt(rowIndex, "username"):
		return {'background': 'FF8A8A'}
	else:
		return {'background': 'white'} 
2 Likes