Query kb table and return content of kb

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2018 02:12 PM
I need to modify the content of my information of my Knowledge Articles. Because the KB's are under a specific knowledge base and a category. I am querying kb_knowledge and filtering with to get the records to my kb_category which is test. I was able to get the information of my KB from my test category. My script in my background is returning me the information of all the KB's associated. The information is in HTML format. I want to be able to find the string that starts after " and ends with # . and replace it with only #.
Example:
From:
href="https://developer.com/test/academicregistrationmetrics#/definitions/date"
To:
href="#/definitions/date"
I have tried several things but I am unable to do such a things.
Code:
var array = [];
var kb= new GlideRecord("kb_knowledge");
kb.addQuery('kb_knowledge_base', '5dd8778a13ac9300be81bb722244b051');
kb.addQuery('kb_category', '88a3250313d59780be81bb722244b0b7');
kb.addNotNullQuery('text'); //information from my KB
//kb.addQuery('text' , 'STARTSWITH', 'href'); //doesn't work
kb.query();
while (kb.next()){
array.push(kb.text.toString());
// var first = array.indexOf("="); //doesnt work
// var last = array.indexOf("#"); //doesnt work
//var final = array.substring(first, last); //doesnt work
gs.print(array);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2018 12:30 AM
You need a regex for that, see for example in my Background scripts:
var text = 'href="https://developer.com/test/academicregistrationmetrics#/definitions/date"';
gs.print(text);
var result = text.replace(/https.*#/g, "#");
gs.print(result);
with a result of:
[0:00:00.005] Script completed in scope global: script
*** Script: href="https://developer.com/test/academicregistrationmetrics#/definitions/date"
*** Script: href="#/definitions/date"
Hope this helps.
Regards,
Sergiu