Ignition 7.9 Table Dynamic Dropdown List on String Column

I am using the following code to attempt to populate the translation Map of a table. Using this combined with a cell update binding should allow for a dynamic drop down list in the cell.

The problem I am having is that the code works for two of the columns but the third for whatever reason just doesn’t seem to take. I separated the code for the translateStep property to insure that I was doing everything the same way. Doesn’t seem to matter what I do though, the mapping just doesn’t show up for that column. I have attached a couple screen shots to show the cell binding and the table customizer. As you can see there is a value in the translateMap for the Step Code column but the table customizer shows no mappings.

I have tried manually checking the “Use Translation List” check box but still no dice.

Any help is appreciated.

if event.propertyName == 'translateItem':
	
	tIStr = '<list>'
	tUStr = '<list>'
	
	ds = event.source.translateItem
	
	for row in range(ds.rowCount):
		if str(ds.getValueAt(row,1)) <> 'None':
			tIStr = tIStr + '<stringpair><key>' + str(ds.getValueAt(row,0)) + '</key><value>' + ds.getValueAt(row,1) + '</value></stringpair>'
			tUStr = tUStr + '<stringpair><key>' + str(ds.getValueAt(row,0)) + '</key><value>' + ds.getValueAt(row,2) + '</value></stringpair>'
	tIStr = tIStr + '</list>'
	tUStr = tUStr + '</list>'
	
	event.source.translateItemStr = tIStr
	event.source.translateUnitStr = tUStr
	
elif event.propertyName == 'translateStep':
	
	tSStr = '<list>'
	
	ds = event.source.translateStep
	
	for row in range(ds.rowCount):
		tSStr = tSStr + '<stringpaiir><key>' + str(ds.getValueAt(row,0)) + '</key><value>' + ds.getValueAt(row,1) + '</value></stringpair>'
		
	tSStr = tSStr + '</list>'
	
	event.source.translateStepStr = tSStr

After some further digging, and correcting the incorrect spelling of ‘stringpair’ in my original code, it turns out that the real issue is that the underlying data in my values is not ‘HTML Safe’ meaning that it doesn’t properly escape special characters.

Now I am just looking for an easy way to do that.

Any help is still appreciated.

Final working script for any who happens upon this post and might have the same issue.

It’s important that what ever string you put into the translateMap for the column be valid HTML. I used the str.replace() method to do this, but I’m not sure if there is possibly another method that is more comprehensive than this. For instance I have not accounted for any special character other than the ‘&’ in this code.

if event.propertyName == 'translateItem':
	
	tIStr = '<list>'
	tUStr = '<list>'
	tSStr = '<list>'
	
	ds = event.source.translateItem
	
	for row in range(ds.rowCount):
		if str(ds.getValueAt(row,1)) == 'None':
			tIStr = tIStr + '<stringpair><key>' + str(ds.getValueAt(row,0)) + '</key><value></value></stringpair>'
		else:
			tIStr = tIStr + '<stringpair><key>' + str(ds.getValueAt(row,0)) + '</key><value>' + ds.getValueAt(row,1) + '</value></stringpair>'
		
		tUStr = tUStr + '<stringpair><key>' + str(ds.getValueAt(row,0)) + '</key><value>' + ds.getValueAt(row,2) + '</value></stringpair>'
		tSStr = tSStr + '<stringpair><key>' + str(ds.getValueAt(row,0)) + '</key><value>' + ds.getValueAt(row,3).replace('&','&amp;') + '</value></stringpair>'
					
	tIStr = tIStr + '</list>'
	tUStr = tUStr + '</list>'
	tSStr = tSStr + '</list>'
	
	event.source.translateItemStr = tIStr
	event.source.translateUnitStr = tUStr
	event.source.translateStepStr = tSStr
2 Likes

Ignition includes the Apache Commons Lang3 library, which has StringEscapeUtils.escapeHtml4() available. Use it like so:

from org.apache.commons.lang3 import StringEscapeUtils
...
tSStr = tSStr + '<stringpair><key>' + str(ds.getValueAt(row,0)) + '</key><value>' + StringEscapeUtils.escapeHtml4(ds.getValueAt(row,3)) + '</value></stringpair>'
1 Like

The Python standard library’s urllib is also a good choice for this, with the quote() and quote_plus() functions.

1 Like