The CreatorCon Call for Content is officially open! Get started here.

Find Hyperlink text in the Knowledge Article content

AnilREddy1408
Tera Contributor

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

 

1 REPLY 1

Syedmd08
Kilo Guru

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:

  1. Navigate to the Business Rules application in ServiceNow.
  2. Click the "New" button to create a new business rule.
  3. Give the business rule a name, such as "Retiring KB Articles with Hyperlinks."
  4. Set the table to "Knowledge" and set the trigger to "Before Query."
  5. 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!