Table translation map can't parse non-ASCII

There is a problem when using non ASCII characters in the translationMap, no errors are shown, the translation mapping just doesn’t work.

I found I can work around the problem by limiting the translationMap to only contain the first 128 characters in the codepage.

import system

#print "property: " + event.propertyName
if event.propertyName == "customerLookup":
  data = system.dataset.toPyDataSet(event.newValue)
  kvpData = ["<list>",]

  for row in data:
    key = row[0]
    value = str(row[1]).replace("&", "")
    value = "".join([x for x in value if ord(x) < 128])
    kvpData.append("<stringpair><key>%s</key><value>%s</value></stringpair>" % (key, value))

  kvpData.append("</list>")
  event.source.customerList = "".join(kvpData)

I’m not quite sure what translation map you’re talking about, or where the given code is being run from.

Checkout the binding on the columnAttributes and the scripting on the propertyChanged event on the table.
SampleDB.sql (27.4 KB)
example.vwin (87.4 KB)

EDIT. I missed a crucial part of this: the reason that a join isn’t used is to get the nice dropdown list for the translated column for edit-ability.

[del]Wow, never seen a setup like that. Why in the world aren’t you just joining the two tables together?

As in, get rid of the customerLookup, customerList, script, the translation mapping, and the binding on column attributes data, and change the query on Data to:[/del]

SELECT Co.ID, Cu.Name, Co.Firstname, Co.Lastname, Co.Title, Co.Phone, Co.Email FROM Contacts Co JOIN Customers Cu ON Co.CustomerID = Cu.id

Ok, I fixed the underlying problem for the non-ascii characters. The translation map is now correctly interpreted as UTF-8.

Your script should now look like this: (you still need to escape the ampersands, but here’s the correct way to do it so that they don’t disappear)

[code]import system

print “property: " + event.propertyName
if event.propertyName == “customerLookup”:
data = system.dataset.toPyDataSet(event.newValue)
kvpData = [”",]

for row in data:
  key = row[0]
  value = str(row[1]).replace("&", "&amp;")
  kvpData.append("<stringpair><key>%s</key><value>%s</value></stringpair>" % (key, value))

kvpData.append("</list>")
event.source.customerList = "".join(kvpData)[/code]