- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2024 07:47 PM
I have a field with the attribute knowledge_search, and I want the search criteria to search from a certain Knowledge base.
I'm thinking to utilize the knowledge_custom dictionary attribute, but I'm unsure how to use this. I've already checked on the documentation.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2024 04:23 PM - edited 03-24-2024 04:24 PM
Hey @Emmanuel Jay Mu,
Didn't find much from the documentation but I did find an OOB example where knowledge_custom was used.
Within an HR Case table, the 'short_description' field has a dictionary override with the following attributes:
no_truncate=true,knowledge_search=true,knowledge_custom=customKnowledgeSearch,ts_weight=10
The 'customKnowledgeSearch' is an OOB UI Script - {instanceURL}/sys_ui_script.do?sys_id=98d599d553221200eb7c0a1806dc343d
function customKnowledgeSearch(searchText, elementName) {
var kb_url_prefix = (document.getElementById("kb_url_prefix") ? document.getElementById("kb_url_prefix").value : 'kb');
var usev2search = elementName.getAttribute('data-legacy-renderer');
var url;
var kb_knowledge_base="bb0370019f22120047a2d126c42e7073";
if (usev2search == 'true') {
url = 'kb_find.do?sysparm_search=' + encodeURIComponent(searchText);
url += "&sysparm_nameofstack=kbpop";
url += "&sysparm_kb="+kb_knowledge_base;
url += "&sysparm_kb_search_table=sn_hr_core_case";
url += "&sysparm_operator=IR_AND_OR_QUERY";
} else {
url = kb_url_prefix+'?id=kb_search&spa=1&resources=Knowledge&query='+ encodeURIComponent(searchText);
url += '&sysparm_kb_search_table=sn_hr_core_case';
url += "&sysparm_kb_knowledge_base="+kb_knowledge_base;
}
popupOpenStandard(url);
}
That should give you a good starting point, hope it helps. Cheers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2024 04:23 PM - edited 03-24-2024 04:24 PM
Hey @Emmanuel Jay Mu,
Didn't find much from the documentation but I did find an OOB example where knowledge_custom was used.
Within an HR Case table, the 'short_description' field has a dictionary override with the following attributes:
no_truncate=true,knowledge_search=true,knowledge_custom=customKnowledgeSearch,ts_weight=10
The 'customKnowledgeSearch' is an OOB UI Script - {instanceURL}/sys_ui_script.do?sys_id=98d599d553221200eb7c0a1806dc343d
function customKnowledgeSearch(searchText, elementName) {
var kb_url_prefix = (document.getElementById("kb_url_prefix") ? document.getElementById("kb_url_prefix").value : 'kb');
var usev2search = elementName.getAttribute('data-legacy-renderer');
var url;
var kb_knowledge_base="bb0370019f22120047a2d126c42e7073";
if (usev2search == 'true') {
url = 'kb_find.do?sysparm_search=' + encodeURIComponent(searchText);
url += "&sysparm_nameofstack=kbpop";
url += "&sysparm_kb="+kb_knowledge_base;
url += "&sysparm_kb_search_table=sn_hr_core_case";
url += "&sysparm_operator=IR_AND_OR_QUERY";
} else {
url = kb_url_prefix+'?id=kb_search&spa=1&resources=Knowledge&query='+ encodeURIComponent(searchText);
url += '&sysparm_kb_search_table=sn_hr_core_case';
url += "&sysparm_kb_knowledge_base="+kb_knowledge_base;
}
popupOpenStandard(url);
}
That should give you a good starting point, hope it helps. Cheers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2024 05:34 PM
Thanks @James Chun, checked on this item once again.
I've tried above UI Script on a scoped application and is throwing a console error, see below:
I was shared with a KB article to address this in KB0822953, on top of the UI script an onLoad Client script should be added:
ScriptLoader.getScripts('sn_hr_core.customKnowledgeSearch.jsdbx', function() {
customKnowledgeSearch(searchText, elementName);
});