- 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-02-2023 12:28 AM
Hi @Ankur Bawiskar ,
Please find below code which we are using to remove the html tags, we need to remove the special character as well when copied from html field to string field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-02-2023 12:54 AM
Hi @Sagar S ,
Try below script it will work.
var gr3 = new GlideRecord("u_exception_request");
gr3.query();
while (gr3.next()) {
var htmlText = gr3.u_short_description;
// Remove HTML tags
var cleanedText = htmlText.replace(/<[^>]*>/g, '');
// Remove special characters
cleanedText = cleanedText.replace(/[^\w\s]/g, '');
gr3.u_exception_short_description = cleanedText;
gr3.update();
}
Thanks,
Anand
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-02-2023 01:14 AM
Hi @Anand Kumar P ,
Thanks for your reply. I tried for one record by using above script but it didn't work.
Regards,
Sagar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-02-2023 02:21 AM
Hi @Sagar S ,
Try below script
var gr3 = new GlideRecord("u_exception_request");
gr3.query();
while (gr3.next()) {
var htmlText = gr3.u_short_description;
var get1=new GlideSPScriptable().stripHTML(htmlText);
var value1 = get1.replace(/[^a-zA-Z0-9]+/g, '-'); //
var value2 = value1.replace(/^-|-$/g, '');
gr3.u_exception_short_description = value2;
gr3.update();
}
Thanks,
Anand
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-02-2023 03:41 AM
It didn't work, attaching the screenshot. In the below screenshot exception short description is string field and short description is HTML field. As you can see # and & is still coming