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

Return Knowledge Base Title(s) from a System Property, into a Catalog Item variable

chatsaurav19
Tera Contributor

Hi All,

 

There is a system property which holds the 'sys_ids' of the knowledge bases ( 'kb_knowledge_base' table ).

 

The requirement is to fetch those 'sys_ids' from the system property and return the 'title' of those knowledge bases in a Catalog Item variable as a drop down choice list. 

 

I understand that I will need to define an advanced reference qualifier to fetch those values but could someone help me how to write the script include to get return those values?

 

I was trying something like this below:::

 

var arr = [];

var arr1 = [];

var gr = new GlideRecord('<system_property>');

gr.addQuery('sys_id', '<sys_id_of_the_system_property>');

gr.query();

if(gr.next()){

  arr.push(gr.values); //values 

}

 

for (var i = 0; i<=arr.length; i++){

    var gr1 = new GlideRecord('kb_knowledge_base');

    gr1.addQuery('sys_id', 'arr[i]');

   if(gr1.next()){

      arr1.push(gr1.title);

   }

return JSON.stringify(arr1);

}

 

I need some more correction so will be glad if someone could help me out.

 

Regards,

Saurabh Chatterjee

 

1 ACCEPTED SOLUTION

SANDEEP28
Mega Sage

@chatsaurav19 For this requirement, you can simply add below one line of code in "Reference qualifier." Script include is not required here. I tested this and its working fine. I have added "Active = true", just to show only active KB bases.

 

javascript&colon; 'sys_idIN'+ gs.getProperty('KnowledgeBaseList') +'^active=true';

 

SANDEEP28_1-1694518198913.png

 

 

Replace your system property name here in place of "KnowledgeBaseList".

Also in your system property, list of sys_id's should be mentioned as comma separated like below

 

SANDEEP28_0-1694517854918.png

 

If I could help you with your Query then, please hit the Thumb Icon and mark as Correct !!

 

View solution in original post

3 REPLIES 3

Voona Rohila
Mega Patron
Mega Patron

Hi @chatsaurav19 

Is your field type choice or reference? 

If choice then try this code:

 

var kb_sysid = gs.getProperty('property_name'); //give the property name here.
var arr1 = [];
var gr1 = new GlideRecord('kb_knowledge_base');
gr1.addQuery('sys_idIN' + kb_sysid);
while (gr1.next()) {
    arr1.push(gr1.title.toString());
}
return JSON.stringify(arr1);

 

 

 


Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP

SANDEEP28
Mega Sage

@chatsaurav19 For this requirement, you can simply add below one line of code in "Reference qualifier." Script include is not required here. I tested this and its working fine. I have added "Active = true", just to show only active KB bases.

 

javascript&colon; 'sys_idIN'+ gs.getProperty('KnowledgeBaseList') +'^active=true';

 

SANDEEP28_1-1694518198913.png

 

 

Replace your system property name here in place of "KnowledgeBaseList".

Also in your system property, list of sys_id's should be mentioned as comma separated like below

 

SANDEEP28_0-1694517854918.png

 

If I could help you with your Query then, please hit the Thumb Icon and mark as Correct !!

 

Hi @SANDEEP28 

 

Thanks a lot! it worked! Can you also please let me know how to show this is as a drop down choice list? It is actually showing up as a lookup icon.

 

 

Hi @Voona Rohila 

 

Thanks for the help! Actually it is a reference field.

 

Regards,

Saurabh