You can do this in Java. You can get the length of a String provided an encoding. Truncating is tricky, though, because you could just hit the middle of multi byte character…
The web searches I did were not helpful in doing it in Javascript.
I played around with getting the bytes length in Java. I think you would have to go an get each “character” individually from the original length in bytes. Then add them all up. Unfortunately the java.lang.String.getBytes() method seems not to be recognized by Servoy/javascript. I think you can do it properly if someone made a plugin in java and did it all within there.