Is it possible to mass update word wrapped hyperlink in knowledge articles?

kirthi1
Tera Contributor

I have about 500+ knowledge articles where I need to mass update word wrapped hyperlink like the below screenshot.

the hyperlink that is word wrapped here has the wrong link and is not routing to the knowledge article mentioned here in the KB article.

The URL should have been - 

https://service-now.com/kb_view.do?sysparm_article=KB0012707

But is the below link, which is not allowing the users on the portal to see the knowledge article

https://.service-now.com/nav_to.do?uri=%2Fkb_view.do%3Fsysparm_article%3DKB0012707

 

find_real_file.png

Any help is greatly appreciated. 

I am honestly not getting ideas to approach this issue.

6 REPLIES 6

sachin_namjoshi
Kilo Patron
Kilo Patron

You will need to configure and run fix script below to change URL

The below script will find and update all of the articles with the correct URL:

 

var srcStr = oldURL; //Replace with url you want to replace
var fxdStr = newURL; //Replace with new url
var r = new GlideRecord('kb_knowledge');
r.addQuery('text','CONTAINS',srcStr);
r.query();
while(r.next()){

  var txt = r.text.toString();
  var fixed = txt.replace(srcStr,fxdStr);
  r.text = fixed;
  r.setWorkflow(false);
  r.update();
  
}

 

Regards,

Sachin

Hi Sachin, 

Thank you for responding!

I am not sure what to include in the oldURL and the newUrl per your script above, as its not in the form of a URL/hyperlink and the its in the form of a hyperlink in a word text like this -

KB0012707

I tried to include with this in the background script but no results-

(Note: the link is instance is there when I ran the script)

var srcStr = https://.service-now.com/nav_to.do?uri=%2Fkb_view.do%3Fsysparm_article%3DKB0012707; //Replace with url you want to replace


var fxdStr = https://.service-now.com/kb_view.do?sysparm_article=KB0012707; //Replace with new url
var r = new GlideRecord('kb_knowledge');
r.addQuery('text','CONTAINS',srcStr);
r.query();
while(r.next()){

var txt = r.text.toString();
var fixed = txt.replace(srcStr,fxdStr);
r.text = fixed;
r.setWorkflow(false);
r.update();

}

Please let me know what am I missing.

 

 

use below code as per your requirement

Change instance name as per your instance configuration.

var srcStr = "https://dev41006.service-now.com/nav_to.do?uri=%2Fkb_view.do%3Fsysparm_article%3DKB0012707"; //Replace with url you want to replace


var fxdStr = "https://dev41006.service-now.com/kb_view.do?sysparm_article=KB0012707"; //Replace with new url
var r = new GlideRecord('kb_knowledge');
r.addQuery('text','CONTAINS',srcStr);
r.query();
while(r.next()){

var txt = r.text.toString();
var fixed = txt.replace(srcStr,fxdStr);
r.text = fixed;
r.setWorkflow(false);
r.update();

}

Hi Sachin, 

I tried by implementing as you suggested above ,but no luck.

I could be explaining it not to point. 

I am trying to update the hyperlink behind the word/number of the KB0012707 (this number is just as an example).

from this is how the current hyperlink is 
https://.service-now.com/nav_to.do?uri=%2Fkb_view.do%3Fsysparm_article%3D

to this one which is the correct one -

https://.service-now.com/kb_view.do?sysparm_article=

as there are so many articles incorrect hyperlink.

find_real_file.png

Could you explain what does the 'text' do in this code and if I have replace this part?

 

var fxdStr = "https://dev41006.service-now.com/kb_view.do?sysparm_article=KB0012707"; //Replace with new url

var r = new GlideRecord('kb_knowledge');

r.addQuery('text','CONTAINS',srcStr);

r.query();

while(r.next()){

 

var txt = r.text.toString();

var fixed = txt.replace(srcStr,fxdStr);

r.text = fixed;

r.setWorkflow(false);

r.update();

 

}