How to find a specific class in HTML and replace with null using javascript
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-04-2022 01:59 PM
I have imported collapsed content in ServiceNow and want to expand it , to do that so I need to find the highlighted text using JavaScript and replace it with null for every field that contain collapsed content, I am not sure whether to use regex or simple find() method. also not sure how we can achieve it without removing height style as collapse content doesn't get expanded unless we remove height along with class name. please advise.
- Labels:
-
Knowledge Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-04-2022 02:36 PM
Hi, unfortunately a partial screenshot doesn't really explain the end to end requirement,
but assuming that the html is just a text field in a record? a simple scripted GlideRecord while loop with replaceAll('valueToReplace', ''); and update(); should work.
A simpler\easier option might be to filter for your list of records that need updating.
Export to xml
Then user a text editor to find/replace
Save the updated xml file to another location
Import the updated xml
As long as you save the updated xml file to a different location on your PC then you have a backup of the original data and can restore (or try again) if there are issues.
And as your testing in a dev instance, what can possibly go wrong that can’t be fixed before deployment to prod.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-07-2022 01:57 AM
@Tony Chatfield1 I can use simple scripted GlideRecord while loop with replaceAll('valueToReplace', ''); but if at some placess that 'class = collapse" is required? how can we avoid that.