cancel
Showing results for 
Search instead for 
Did you mean: 

Character changes to unidentified when passing to Java Script

0 Kudos

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

Accepted Solutions (0)

Answers (2)

Answers (2)

Sriprasadsbhat
Active Contributor
0 Kudos

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 = builder.build(is);

................... 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"));
  	message.setBody(is);
  	return message;
}

Regards,

Sriprasad Shivaram Bhat

SergioG_TX
Active Contributor
0 Kudos

make sure your enconding is utf-8