Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Can someone share on how the Dictionary Attribute: knowledge_custom, is being used?

Emmanuel Jay Mu
Tera Contributor

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.

1 ACCEPTED SOLUTION

James Chun
Kilo Patron

Hey @Emmanuel Jay Mu,

 

Didn't find much from the documentation but I did find an OOB example where knowledge_custom was used.

 

JamesChun_0-1711322619868.png

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

View solution in original post

2 REPLIES 2

James Chun
Kilo Patron

Hey @Emmanuel Jay Mu,

 

Didn't find much from the documentation but I did find an OOB example where knowledge_custom was used.

 

JamesChun_0-1711322619868.png

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

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:

EmmanuelJayMu_1-1713918394649.png

 

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);
});