The CreatorCon Call for Content is officially open! Get started here.

Create Known Error article custom

felipe14
Tera Contributor

Hi everyone, I need to create a Create known error article but it must be created in a specific knowledge base and not the default one.

 

 

my code: 

(function createKEServer(current, action) {
// Sys_id da KB Data Center CloudCO
var KB_SYSID = '84aca5a4fbebee5819d0f40d4eefdcb4';
var TEMPLATE_NAME = 'Known Error';

// Cria novo artigo de Knowledge
var article = new GlideRecord('kb_knowledge');
article.initialize();
article.setWorkflow(false); // Evita que BRs ou workflows sobrescrevam campos

// Define KB fixa
article.setValue('kb_knowledge_base', KB_SYSID);

// Define template Known Error
var template = new GlideRecord('kb_template');
template.addQuery('name', TEMPLATE_NAME);
template.query();
if (template.next()) {
article.setValue('kb_template', template.sys_id);
}

// Copia campos do Problem
article.setValue('short_description', current.getValue('short_description'));
article.setValue('text', current.getValue('description'));
article.setValue('problem', current.getValue('sys_id'));

// Insere o artigo
var articleSysId = article.insert();

// Força a KB novamente após insert (impede sobrescrita por BRs)
if (articleSysId) {
var fix = new GlideRecord('kb_knowledge');
if (fix.get(articleSysId)) {
fix.setWorkflow(false);
fix.setValue('kb_knowledge_base', KB_SYSID);
fix.update();
}

// Redireciona para o artigo criado
action.setReturnURL(current);
action.setRedirectURL('/kb_knowledge.do?sys_id=' + articleSysId);
} else {
gs.error('Falha ao criar artigo de Knowledge.');
gs.addErrorMessage('Erro ao criar o artigo. Verifique os logs.');
action.setRedirectURL(current);
}
})(current, action);

1 REPLY 1

Abbas_5
Tera Sage
Tera Sage

Hello @felipe14,

Please refer to the link below:
https://www.servicenow.com/docs/bundle/zurich-it-service-management/page/product/problem-management/...

 

If it is helpful, please mark it as helpful and accept the correct solution. By referring to this solution in the future, it will be helpful to them.

 

Thanks & Regards,

Abbas Shaik