- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2023 03:50 AM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2023 04:26 AM - edited 09-12-2023 04:30 AM
@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: 'sys_idIN'+ gs.getProperty('KnowledgeBaseList') +'^active=true';
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
If I could help you with your Query then, please hit the Thumb Icon and mark as Correct !!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2023 04:03 AM - edited 09-12-2023 04:55 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2023 04:26 AM - edited 09-12-2023 04:30 AM
@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: 'sys_idIN'+ gs.getProperty('KnowledgeBaseList') +'^active=true';
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
If I could help you with your Query then, please hit the Thumb Icon and mark as Correct !!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2023 07:28 AM
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.
Thanks for the help! Actually it is a reference field.
Regards,
Saurabh