Find Hyperlink text in the Knowledge Article content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2023 07:19 AM
I have requirement to show error message if Knowledge Article content having hyperlink KB article reference.
If KB article(KBXXXX3) content having below references.Test1 is hyperlink add and Test2 is normal text.
KBXXXXXXX :Test1
KBXXXXXXX2:Test2
if user tries to make KBXXXX3 to retire ,error message should come up to remove hyperlink for KBXXXXXXX :Test1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2023 11:24 AM
o accomplish this requirement, you can create a business rule in ServiceNow that checks the content of the Knowledge Article when it is being retired. If the content contains a hyperlink to a KB article, the rule will display an error message prompting the user to remove the hyperlink before retiring the article.
Here's an example of a business rule that you can use to implement this functionality:
- Navigate to the Business Rules application in ServiceNow.
- Click the "New" button to create a new business rule.
- Give the business rule a name, such as "Retiring KB Articles with Hyperlinks."
- Set the table to "Knowledge" and set the trigger to "Before Query."
- In the Advanced field, enter the following script:
(function executeRule(current, previous /*null when async*/) {
var kbContent = current.getValue("text");
if (kbContent.indexOf("<a href=\"/kb_view.do?sysparm_article=") != -1) {
gs.addErrorMessage("Error: Please remove any hyperlinks to KB articles before retiring this Knowledge Article.");
}
})(current, previous);
This script checks the content of the Knowledge Article (stored in the "text" field) for the presence of a hyperlink to a KB article. If such a hyperlink is found, the script displays an error message prompting the user to remove the hyperlink before retiring the article.
Save the business rule and test it out by attempting to retire a Knowledge Article that contains a hyperlink to a KB article. You should see the error message appear, preventing you from retiring the article until the hyperlink is removed.
Please mark my reply as Helpful and/or Accept Solution, if applicable. Thanks!