- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-11-2019 02:49 PM
Below is the server side script for a widget.
I am receiving the shortDescription from the client controller.
All works well until the supplied input.shortDescription contains a single quote (eg. "James's new laptop and phone").
What is the best way to escape/encode/decode the string in this situation?
var cart_item = new GlideRecord('sc_cart_item');
cart_item.addQuery('cart', "" + cartJS.getCartID());
gs.log('looking for items in cart:' + cartJS.getCartID());
cart_item.query();
if(cart_item.next()) {
cart_item.hints = "<hints><entry key='sysparm_processing_hint' value='setfield:request.short_description=" + input.shortDescription + "'/></hints>";
cart_item.update();
}
Thanks!
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-11-2019 03:19 PM
Looking at https://community.servicenow.com/community?id=community_question&sys_id=35298be1db5cdbc01dcaf3231f961948 it seems like I have to write a business rule to decode it on insert..

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-11-2019 03:00 PM
You need to use escape(\) character when there is ' character.
Replace ' with \'
Ex: James\'s new laptop and phone
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-11-2019 03:07 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-11-2019 03:29 PM
Can you share the script that you are using for encoding?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-11-2019 03:19 PM
Looking at https://community.servicenow.com/community?id=community_question&sys_id=35298be1db5cdbc01dcaf3231f961948 it seems like I have to write a business rule to decode it on insert..