How to find a specific class in HTML and replace with null using javascript

GD11
Tera Expert

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.

GovindDhande_0-1664916759058.png

 

2 REPLIES 2

Tony Chatfield1
Kilo Patron

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.

@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.