How to edit the function of "Attach" button on related search record in incident
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-22-2023 11:35 PM
Whenever i click on attach button it general the KB article url/link and add that to additional comment, but i want that when we click on attach button it should actually fetch that KB article no. from the additonal comment and add it to the new reference field "Knowledge article" that i just have created.
I do not want to amend the OOB script include "cxs_Knowledge".
Can we create a on change client script of BR through which i can acive this.
Below is the Client script i got where there are editing that URL getting pasted in additional comment, so can we edit this script of acive what i want.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
if(newValue.includes('kb_view')){
// gets form value from Additional comments fields
var comment = g_form.getValue('comments');
// retrieve KB link between [code] blocks
var commentLink = comment.substring(
comment.lastIndexOf('[code]') + 6,
comment.lastIndexOf('[/code]')
);
// retrieve KB number from URL
var kbNumberSub = commentLink.match(' >(.*) : ')[1];
var kbNumber = trim(kbNumberSub);
// query to retrieve KB article data
var gr = new GlideRecord('kb_knowledge');
gr.addQuery('number', kbNumber);
gr.orderByDesc('sys_created_on');
gr.setLimit(1);
gr.query();
gr.next();
// KB Number
var KBNum = gr.getValue('number');
// KB Title
var KBTitle = gr.getValue('short_description');
// KB Knowledge Base
var KBKnowledgeBase = gr.getValue('kb_knowledge_base');
// query to retrieve portal data
var url = new GlideRecord('sp_portal');
url.addQuery('kb_knowledge_base', KBKnowledgeBase);
url.orderByDesc('sys_created_on');
url.setLimit(1);
url.query();
url.next();
// portal URL suffix
var portal = url.getValue('url_suffix');
// replace Additional comments fields with new URL
g_form.setValue("comments", newValue.replace(comment, "[code]<a title='"+KBNum+": "+KBTitle+"' href='"+portal+"?id=kb_article&sysparm_article="+KBNum+"'>"+KBNum+": "+KBTitle+"</a>[/code]"));
}
}
0 REPLIES 0