Escape XML Characters
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2011 11:29 AM
Hello,
I have an XML SOAP request that gets sent out regularly to an external vendor. Our vendor is saying that we need to HTML encode our apostrophes in our messages. These show up in user last names such as O'Donnell.
I have tried to replace the apostrophe characters using the following code:
//FILTER OUT SPECIAL CHARACTERS FOR XML REQUEST
var apostrophe = "'";
defaultReporterFirstName = defaultReporterFirstName.replace(/'/g, apostrophe);
defaultReporterLastName = defaultReporterLastName.replace(/'/g, apostrophe);
The issue now is it appears that Service Now is HTML encoding the ampersand character at the beginning of the string, but this is breaking the HTML encoding for the apostrophe.
O'DonnellWeb Ticket
Is there a way I can HTML encode apostrophe characters in XML?
Thanks!
Mark Didrikson
- Labels:
-
Integrations
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2011 11:35 AM
Here is the XML output:
<ReporterLastName>O'Donnell</ReporterLastName><Origin>Web Ticket</Origin>
Thanks!
Mark Didrikson
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2011 12:07 PM
One trick I do when having to hard code an escape in javascript code that is stored in service-now is to write it like this:
[code lang='javascript']
var apostrophe = "&"+"apos;";
[/code]
This will prevent the script saving action from converting the string to an actual apostrophe.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2011 01:32 PM
Thanks John. I tried that out, but I'm still getting the same issue.
<ReporterLastName>O'Donnell</ReporterLastName><Origin>Web Ticket</Origin>
//FILTER OUT SPECIAL CHARACTERS FOR XML REQUEST
var apostrophe = "&"+"apos;";
defaultReporterFirstName = defaultReporterFirstName.replace(/'/g, apostrophe);
defaultReporterLastName = defaultReporterLastName.replace(/'/g, apostrophe);
This is occurring in a Business Rule, if that matters.
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2011 01:47 PM
Try:
[code lang='javascript']
var apostrophe = "'";
[/code]
OR
[code lang='javascript']
var apostrophe = "'";
[/code]
See if either of those work.