- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-01-2023 10:01 PM
Hi,
We have HTML field called "short description" and string field called "exception short description", we are copying the values from html field to string field by removing the html tags. now we are facing an issue that special characters is also copying from html field to string field. We would need to remove the special character from the string field and the special character should not copy from html field to string field.
Regards,
Sagar
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-02-2023 04:48 AM
Hi @Sagar S ,
In which script you are populating it.
I have created business rule with below script
Thanks,
Anand
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-01-2023 10:14 PM - edited ‎11-01-2023 10:33 PM
Hi @Sagar S ,
Please refer this script from this article - Remove html tags when copying into a string field
var desc='<p>test1</p>';
gs.print('Original '+desc);
desc= desc.replace(/<\/?[^>]+(>|$)/g, "");
gs.print('html sanitized:'+desc);
Please mark the answer correct/helpful based on Impact.
Regards, Anup
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-01-2023 10:58 PM - edited ‎11-01-2023 11:00 PM
Hi @Sagar S ,
var yourHtmlStr='<p>html tah@*(@())</p>';
var get1=new GlideSPScriptable().stripHTML(yourHtmlStr);
var value1 = get1.replace(/[^a-zA-Z0-9]+/g, '-'); //
var value2 = value1.replace(/^-|-$/g, '');
gs.print(value2);
Please mark it as solution proposed and helpful if it serves your purpose.
Thanks,
Anand
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-01-2023 11:27 PM
Hi @Sagar S,
Can you please try below script:
// Replace special characters in a string field
var fieldValue = "yourStringField"; // Replace 'yourStringField' with the actual field name
var replacedValue = fieldValue.replace(/[^a-zA-Z0-9]/g, '_'); // Replace non-alphanumeric characters with underscores
current.yourStringField = replacedValue;
Please mark the answer correct if it helped you.
Thanks,
Dipen
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-01-2023 11:31 PM
share what script are you using to remove the tags?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader