Skip to Content
avatar image
Former Member

Character changes to unidentified when passing to Java Script

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Oct 27, 2017 at 07:08 PM

    make sure your enconding is utf-8

    Add comment
    10|10000 characters needed characters exceeded

  • 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 = 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

    Add comment
    10|10000 characters needed characters exceeded