how to download knowledge base articles from servicenow through api

Phanikanth
Kilo Contributor

Hi,

I have an api which gives the KB(Knowledgebase ) articles and along with many fileds,I want to download the articles from the api. Please suggest.The below api returning text(artilce),I want to download using servicenow rest api.

API:https://dev82597.service-now.com/api/now/table/kb_knowledge?sysparm_query=short_descriptionLIKESpamand

output:

{
    "result": [
        {
            "parent": "",
            "short_description": "How to Deal with Spam",
            "roles": "",
            "wiki": null,
            "direct": "false",
            "rating": "",
            "description": "",
            "language": "en",
            "source": "",
            "sys_updated_on": "2014-12-19 15:54:36",
            "disable_suggesting": "false",
            "sys_class_name": "kb_knowledge",
            "number": "KB0000011",
            "sys_id": "0b48fd75474321009db4b5b08b9a71c2",
            "use_count": "0",
            "sys_updated_by": "johnoliver.mendoza",
            "flagged": "true",
            "disable_commenting": "false",
            "sys_created_on": "2014-09-09 23:31:10",
            "sys_domain": {
                "link": "https://dev82597.service-now.com/api/now/table/sys_user_group/global",
                "value": "global"
            },
            "valid_to": "2100-01-01",
            "retired": "",
            "workflow_state": "published",
            "text": "<p><span style=\"font-size: 18pt;\"><strong>How to Deal with Spam</strong></span></p>\n<p>Spam has increasingly become a problem on the Internet. While every Internet user receives some spam, email addresses posted to web sites or in newsgroups and chat rooms attract the most spam.</p>\n<p>To reduce the amount of spam you receive:
7 REPLIES 7

Maik Skoddow
Tera Patron
Tera Patron

Hi

unfortunately it is not really clear what your issue is.

Please provide more details and describe better what your expectation is.

Kind regards
Maik

Hi @Maik Skoddow  Cany you please help me related to knowledge article

https://community.servicenow.com/community?id=community_question&sys_id=7678f2efdb514110019ac2230596196a

above is my question link

1. In Knowledge Base the article validity is (ex:1825 = 5years / 2yrs) so article validity populate to Valid to date in Knowledge article to 5 yrs . i have written logic i can add more than 30 days . so(1825+30 days i can add) if i am try to add more than that it should print date in alert .user should select less than yyyy-mm-dd.

i tried printing months it is working as per below script i want print date instead of months

2. if article validity is empty by default valid to date is 2100-01-01 in these case it should print alert from current date to 1year +30= 395 days

below script is i tried for months can anyone help me for date

client script :

function onSubmit() {
//Type appropriate comment here, and begin script below

if (g_scratchpad.isFormValid){
return true;
}

var actionName = g_form.getActionName();

var ga = new GlideAjax('KnowledgeTimeDifference');
ga.addParam('sysparm_name','getDiff');

ga.addParam('sysparm_sysid',g_form.getValue('kb_knowledge_base'));
ga.addParam('sysparm_start',g_form.getValue('valid_to'));

ga.getXMLAnswer(function(answer) {
answer = JSON.parse(answer);

if(answer.status == false)
{
alert("Please select the Valid to date less than "+answer.days+" months greater than today's date");
}
else
{
g_scratchpad.isFormValid = true;
g_form.submit(actionName);
}


});

return false;

}

script include:

var KnowledgeTimeDifference = Class.create();
KnowledgeTimeDifference.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getDiff: function() {

var arval = '';
//var stDateVar;
var sysid = this.getParameter('sysparm_sysid');

var gr = new GlideRecord('kb_knowledge_base');
gr.addQuery('sys_id', sysid);
gr.query();

if (gr.next()) {
arval = gr.getValue('article_validity');
}
if (arval == null) {
arval = '0';

}

var gdt1 = new GlideDateTime();
gdt1.addDaysUTC(parseInt(arval) + 30);

var days = 0;

if (arval == '0') {
days = 13;//yyyy-mm-dd


} else {
days = Math.round((parseInt(arval) + 30) / 30);

}


var start = this.getParameter('sysparm_start');
var gdt2 = new GlideDateTime(start);

var dur = GlideDateTime.subtract(gdt1, gdt2);
var date = new GlideDate();
date.setValue(gdt2);
date.addMonths(days);
var dif = dur.getNumericValue();
var js = {};

if (dif <= 0) {

js.status = true;
} else {
js.days = days;
js.status = false;
}

return JSON.stringify(js);


},

 

type: 'KnowledgeTimeDifference'
});

 

 

 

Hi,

I want to download KB articles from servicenow through API.

Exmaple:

API:https://dev82597.service-now.com/api/now/table/kb_knowledge?sysparm_query=short_descriptionLIKESpamand.

In the below output,I have text field with description in below.the test description I want to download in wiki page fomrate.Plz suggest

output:

{
    "result": [
        {
            "parent": "",
            "short_description": "How to Deal with Spam",
            "roles": "",
            "wiki": null,
            "direct": "false",
            "rating": "",
            "description": "",
            "language": "en",
            "source": "",
            "sys_updated_on": "2014-12-19 15:54:36",
            "disable_suggesting": "false",
            "sys_class_name": "kb_knowledge",
            "number": "KB0000011",
            "sys_id": "0b48fd75474321009db4b5b08b9a71c2",
            "use_count": "0",
            "sys_updated_by": "johnoliver.mendoza",
            "flagged": "true",
            "disable_commenting": "false",
            "sys_created_on": "2014-09-09 23:31:10",
            "sys_domain": {
                "link": "https://dev82597.service-now.com/api/now/table/sys_user_group/global",
                "value": "global"
            },
            "valid_to": "2100-01-01",
            "retired": "",
            "workflow_state": "published",
            "text": "<p><span style=\"font-size: 18pt;\"><strong>How to Deal with Spam</strong></span></p>\n<p>Spam has increasingly become a problem on the Internet. While every Internet user receives some spam, email addresses posted to web sites or in newsgroups and chat rooms attract the most spam.</p>\n<p>To reduce the amount of spam you receive:

Hi

sorry, but repeating the same question text as an answer is not really helpful.

Instead you could start by explaining what your understanding of "downloading of knowledge articles" is. Do you expect a Word file? A PDF file? Anything else?

Maik