Need to remove image present in all the knowledge article's Article body.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-16-2022 06:57 AM
Hi Everyone,
We have more than 2k knowledge articles, there is an image present in the template present in the article body for all the articles that needs to be removed.
I have written a script and I am storing the value of the Article body field (in the form of string) in a variable.
My plan is to remove the first <tr> that has that image and update the article field value for each record.
The problem is that the HTML body is coming in form of string and I am trying to replace the first <tr> using javascript string functions. But I am not able to replace it with .replace function.
Here's what I tried in background script so far:
1) Used GlideRecord in kb_knowledge table
2) I am trying to update only 1 article as of now, so adding addQuery with sys_id of that particular article.
3) storing the article body in a variable (in string format)
4) trying to remove all the white spaces between HTML tags using bodyText.replace(/>\s+</g,'><');
5) trying to replace the whole HTML code between <tr></tr> with .replace function -- This is not working.
Here's my background script logic:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-17-2022 05:53 PM
Shouldnt you uncomment this - //gr.update();
Also not sure how crazy this would be but what if you exported xml then somehow opened that file and edited those strings. There are probably other ways as well.
Also what happens if you rename the image file- would that result in image dissapearing?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-21-2024 06:10 AM
This worked for me!I exported a test document and just deleted the reference to the image between the XML tags and reimported. Now test a bulk export, edit and import.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-17-2022 10:24 PM - edited ‎12-17-2022 10:26 PM
@Ashutosh44 Tried and tested solution.
You can use below code to remove the image row.
Please mark as correct answer if this solves your issue.
ServiceNow Community Rising Star, Class of 2023