Skip to Content

Character changes to unidentified when passing to Java Script

Oct 27, 2017 at 05:26 PM


avatar image
Former Member

Hello, guys.

Currently working on a project that involves javascript with HCI PI and when we try to pass the message body to the script other characters turn to this ��, its suppose to be like this é tried to put encoding or parsing the string to byte but failed. what can i do to avoid such error, thanks

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Sergio Guerrero Oct 27, 2017 at 07:08 PM

make sure your enconding is utf-8

10 |10000 characters needed characters left characters exceeded
Sriprasad Shivaram Bhat
Oct 30, 2017 at 05:26 AM

Hello Elpedio,

Agree with Sergio.

You need to maintain character encoding while reading the data in Script and generating output out of your script .Below might help you.

Beginning of the script:

def Message TestData (Message message)
// Extract message body and properties
	def body = message.getBody(String.class);
	def props = message.getProperties();

// Create a new JDOM XML Parser
	SAXBuilder builder = new SAXBuilder();
// Obtain the XML data from the message body received, and build it using the parser
	InputStream is = new ByteArrayInputStream(body.getBytes("UTF-8"));
  	Document doc =;

................... code goes on as per your requirement

After you are done with all the transformation:

// Create a new XMLOutputter object to write the new
	XMLOutputter outputter = new XMLOutputter(Format.getCompactFormat().setOmitDeclaration(true));
// Write the modified XML data into a ByteArrayInputStream Object, which can then be set as the message's body
	is = new ByteArrayInputStream(outputter.outputString(doc).getBytes("UTF-8"));
  	return message;


Sriprasad Shivaram Bhat

10 |10000 characters needed characters left characters exceeded