723 views

Description

If the instance has a language plugin installed, knowledge article translations created prior to activating the I18N - Knowledge Management Internationalization plugin are lost.

Steps to Reproduce

  1. Activate any language plugin.
  2. Create a new article and modify an existing article using a non-English translation.
  3. Activate the I18N - Knowledge Management Internationalization plugin.
  4. Navigate to the articles you created and edited.
    Note that changes made using the non-English translation are migrated to English.

Workaround

Run the following script as a background script. After running the script, one new knowledge article is created in Draft state for each translation. Review these records and publish them as needed.

function copyAttachment(oldKbId, newKbId) {
var queryAttGr = new GlideRecord('sys_attachment');
queryAttGr.addQuery('table_name', 'kb_knowledge');
queryAttGr.addQuery('table_sys_id', oldKbId);
queryAttGr.query();
while (queryAttGr.next()) {
var insertAttGr = new GlideRecord('sys_attachment');
insertAttGr.initialize();
insertAttGr.table_name = queryAttGr.table_name;
insertAttGr.table_sys_id = newKbId;
insertAttGr.file_name = queryAttGr.file_name;
insertAttGr.content_type = queryAttGr.content_type;
insertAttGr.size_bytes = queryAttGr.size_bytes;
insertAttGr.compressed = queryAttGr.compressed;
insertAttGr.size_compressed = queryAttGr.size_compressed;
var attachId = insertAttGr.insert();
var queryDocGr = new GlideRecord('sys_attachment_doc');
queryDocGr.addQuery('sys_attachment', queryAttGr.sys_id);
queryDocGr.query();
while (queryDocGr.next()) {
var insertDocGr = new GlideRecord('sys_attachment_doc');
insertDocGr.initialize();
insertDocGr.sys_attachment = attachId;
insertDocGr.position = queryDocGr.position;
insertDocGr.length = queryDocGr.length;
insertDocGr.data = queryDocGr.data;
insertDocGr.insert();
}
}
}

function assignField(newGr, newField, oldGr,field) {
if (!newGr.isValidField(newField) || !oldGr.isValidField(field))
return ;
newGr[newField] = oldGr[field];
}

function importTranslated(kbGr, titleGr, textGr) {
if (!textGr)
return ;
var newKbGr = new GlideRecord('kb_knowledge');
newKbGr.initialize();
if (titleGr)
assignField(newKbGr, 'language', titleGr, 'language');
else
assignField(newKbGr, 'language', textGr, 'language');
assignField(newKbGr, 'parent', kbGr, 'sys_id');
assignField(newKbGr, 'topic', kbGr, 'topic');
assignField(newKbGr, 'category', kbGr, 'category');
if (kbGr.kb_knowledge_base.kb_version == '3')
newKbGr.workflow_state = 'draft';
else
assignField(newKbGr, 'workflow_state', kbGr, 'workflow_state');
assignField(newKbGr, 'article_type', kbGr, 'article_type');
assignField(newKbGr, 'roles', kbGr, 'roles');
if (titleGr)
assignField(newKbGr, 'short_description', titleGr, 'label');
else
assignField(newKbGr, 'short_description', kbGr, 'short_description');
assignField(newKbGr, 'text', textGr, 'value');
assignField(newKbGr, 'meta', kbGr, 'meta');
assignField(newKbGr, 'source', kbGr, 'source');
assignField(newKbGr, 'flagged', kbGr, 'flagged');
assignField(newKbGr, 'author', kbGr, 'author');
assignField(newKbGr, 'use_count', kbGr, 'use_count');
assignField(newKbGr, 'rating', kbGr, 'rating');
assignField(newKbGr, 'description', kbGr, 'description');
assignField(newKbGr, 'kb_knowledge_base', kbGr, 'kb_knowledge_base');
assignField(newKbGr, 'kb_category', kbGr, 'kb_category');
assignField(newKbGr, 'retired', kbGr, 'retired');
assignField(newKbGr, 'disable_commenting', kbGr, 'disable_commenting');
assignField(newKbGr, 'cmdb_ci', kbGr, 'cmdb_ci');
return newKbGr.insert();
}

function searchTranslated(kbGr) {
var titleGr = new GlideRecord('sys_translated');
var textGr = new GlideRecord('sys_translated_text');
var languages = {};
titleGr.addQuery('name', 'kb_knowledge');
titleGr.addQuery('element', 'short_description');
titleGr.addQuery('value', kbGr.short_description);
titleGr.query();
textGr.addQuery('tablename', 'kb_knowledge');
textGr.addQuery('documentkey', kbGr.sys_id);
textGr.addQuery('fieldname', 'text');
textGr.query();
while (titleGr.next()) {
var lang = titleGr.language;
if (!languages[lang])
languages[lang] = {title: null, text: null};
languages[lang].title = titleGr.sys_id;
}
while (textGr.next()) {
var lang = textGr.language;
if (!languages[lang])
languages[lang] = {title: null, text: null};
languages[lang].text = textGr.sys_id;
}
for (var lang in languages)
if (languages.hasOwnProperty(lang)) {
var titleGr2 = null;
var textGr2 = null;
if (languages[lang].title) {
if (titleGr.get(languages[lang].title))
titleGr2 = titleGr;
}
if (languages[lang].text) {
if (textGr.get(languages[lang].text))
textGr2 = textGr;
}
var newKbId = importTranslated(kbGr, titleGr2, textGr2);
copyAttachment(kbGr.sys_id, newKbId);
}
}

var gr = new GlideRecord('kb_knowledge');
gr.addActiveQuery();
gr.query();
while (gr.next())
searchTranslated(gr);

 


Related Problem: PRB629229

Seen In

Eureka Patch 5
Eureka Patch 8
Fuji Patch 5
Geneva Patch 6
Geneva Patch 7

Fixed In

Fuji Patch 13
Geneva Patch 7
Helsinki Patch 1
Istanbul

Associated Community Threads

There is no data to report.

Article Information

Last Updated:2018-03-06 21:52:19
Published:2015-08-10