- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2024 10:13 AM
Hi,
I'm trying to display the text with special characters from the HTML field in the string field. However, the text is shown with the ASCII characters instead of actual special characters. See the example below
Text in HTML field: Test's
Text in String field: Test's
Code: current.test.replace(/<.*?>/g, '').trim();
Am I missing anything here?
Thanks,
Pavan.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2024 10:48 PM
Hi @Pavan Dev
Try this
var htmlText = current.u_html_field;
var decodedText = htmlText
.replace(/&#(\d+);/g, function(match, dec) {
return String.fromCharCode(dec);
})
.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/&/g, '&')
.replace(/"/g, '"')
.replace(/'/g, "'")
// Add more replacements for other named entities if needed
.replace(/<[^>]*>/g, '')
.trim();
gs.print(decodedText);
OR
// Get the HTML text from the field
var htmlText = current.u_html_field;
// Decode HTML entities
var decodedText = GlideStringUtil.format(htmlText);
// Return the decoded text
return decodedText;
🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2024 01:49 PM
If this is indeed server side script, you can use
new global.GlideSPScriptable().stripHTML('Test's');
to get the plain text variant of an HTML source.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2024 02:38 PM
Hi @Pavan Dev ,
Create business rule with below script
see this
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0721958
If I could help you with your Query then, please hit the Thumb Icon and mark it as Correct !!
Thanks & Regards,
Sumanth Meda