- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-18-2024 08:36 AM
In the UI Action on the Open Submissions form, I want to set the template used.
Right now the OOB code sets the base, but then defaults to the Knowledge template. I want it to default to another template we've created.
I've tried using sys_class_name, but had no luck.
Any ideas would be greatly appreciated.
Here's the OOB code.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-18-2024 09:54 AM
@clktester To use your custom template, you need to explicitly set the kb_template field in your code. Assuming you already have a custom knowledge template created, you can specify its sys_id.
Updated Code:
generateKB();
function generateKB() {
if (current.changes()) {
current.update();
}
var gr = new GlideRecord('kb_knowledge');
gr.initialize();
gr.newRecord();
gr.text = current.text;
gr.source = current.sys_id;
gr.sys_domain = current.sys_domain;
gr.short_description = current.short_description;
gr.valid_to = current.valid_to;
gr.direct = current.direct;
gr.display_attachments = current.display_attachments;
gr.kb_knowledge_base = gs.getProperty("glide.knowman.task_kb", "dfc19531bf2021003f07e2c1ac0739ab");
// Set the custom knowledge template (replace with your template's sys_id)
gr.kb_template = '<your_custom_template_sys_id>';
if (current.hasAttachments()) {
var ids = GlideSysAttachment.copy('kb_submission', current.sys_id, 'kb_knowledge', gr.sys_id);
ids = ids.toArray();
for (var i = 0; i < ids.length; i++) {
var oldandnew = ids[i].split(',');
gr.text = gr.text.toString().replaceAll(oldandnew[0], oldandnew[1]);
}
}
var newID = gr.insert(); gs.addInfoMessage(gs.getMessage("Article {0} created", gr.number));
action.setRedirectURL(gr);
action.setReturnURL(current);
}
Hope this will help you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-18-2024 09:54 AM
@clktester To use your custom template, you need to explicitly set the kb_template field in your code. Assuming you already have a custom knowledge template created, you can specify its sys_id.
Updated Code:
generateKB();
function generateKB() {
if (current.changes()) {
current.update();
}
var gr = new GlideRecord('kb_knowledge');
gr.initialize();
gr.newRecord();
gr.text = current.text;
gr.source = current.sys_id;
gr.sys_domain = current.sys_domain;
gr.short_description = current.short_description;
gr.valid_to = current.valid_to;
gr.direct = current.direct;
gr.display_attachments = current.display_attachments;
gr.kb_knowledge_base = gs.getProperty("glide.knowman.task_kb", "dfc19531bf2021003f07e2c1ac0739ab");
// Set the custom knowledge template (replace with your template's sys_id)
gr.kb_template = '<your_custom_template_sys_id>';
if (current.hasAttachments()) {
var ids = GlideSysAttachment.copy('kb_submission', current.sys_id, 'kb_knowledge', gr.sys_id);
ids = ids.toArray();
for (var i = 0; i < ids.length; i++) {
var oldandnew = ids[i].split(',');
gr.text = gr.text.toString().replaceAll(oldandnew[0], oldandnew[1]);
}
}
var newID = gr.insert(); gs.addInfoMessage(gs.getMessage("Article {0} created", gr.number));
action.setRedirectURL(gr);
action.setReturnURL(current);
}
Hope this will help you.