- 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 04:44 PM
Hi James,
Have you tried using GlideStringUtil to clean up your input?
Code Example:
var shortDesc = GlideStringUtil.escapeAllQuotes(input.shortDescription);
gs.info(shortDesc);
Let me know if this worked for you.
Brent
P.S. If my suggestion helped then please mark as helpful and/or correct so other community members can benefit from this information.