- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-25-2024 10:41 AM
Hello Everyone,
I am working on a task where I need to create translated text for the KB Category.
I will be creating the Configuration Item in English it will create a kb category with the same CI name in English, when the kb category is created, its translated text should be needs to be created in sys_translated_text table for French and German.
I don't want to install Dynamic Translation plugin.
I have French Translations and German Translations plugins installed.
Thank You!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-25-2024 09:25 PM
Hi @RiyazAhamed ,
Ensure you have the French and German translations available for each Configuration Item name. This can be done by maintaining a mapping table or hardcoding it if the list is small.
Then you can write script to insert record in sys_translated_text table using Asyn business rule.
For example
(function executeRule(current, previous /*null when async*/) {
// Define the translations (This can also be fetched from a custom mapping table or an external source)
var translations = {
"Configuration Item Name 1": {
"fr": "Nom de l'élément de configuration 1",
"de": "Konfigurationselementname 1"
},
"Configuration Item Name 2": {
"fr": "Nom de l'élément de configuration 2",
"de": "Konfigurationselementname 2"
}
};
// Get the name of the newly created KB Category
var categoryName = current.name;
// Check if translations exist for this category name
if (translations[categoryName]) {
// Insert French translation
var frenchTranslation = new GlideRecord('sys_translated_text');
frenchTranslation.initialize();
frenchTranslation.field_name = "name"; // Field to translate
frenchTranslation.table_name = "kb_category"; // Target table
frenchTranslation.locale = "fr"; // French locale
frenchTranslation.document_key = current.sys_id.toString(); // Reference to KB category
frenchTranslation.value = translations[categoryName]["fr"];
frenchTranslation.insert();
// Insert German translation
var grt= new GlideRecord('sys_translated_text');
grt.initialize();
grt.field_name = "name"; // Field to translate
grt.table_name = "kb_category"; // Target table
grt.locale = "de"; // German locale
grt.document_key = current.sys_id.toString(); // Reference to KB category
grt.value = translations[categoryName]["de"];
grt.insert();
}
})(current, previous);
-------------------------------------------------------------------------
If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.
Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay
-------------------------------------------------------------------------

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-25-2024 09:18 PM
Have you tried writing a after insert BR on kb_category table? Try the below code in the BR and let me know if it works. -
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-27-2024 01:43 AM
Yes, I have tried the same thing, but now I am facing different issue.
When I am creating a CI keeping my profile language in English it works fine, but when I am creating the same with French language profile, one record for English and one for German is created additionally 2 French record is also created. How to avoid it.
New record in en = 1 de and 1 fr
New record in fr = 1 de and 1 en
New record in de = 1 en and 1 fr
should create

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-27-2024 02:32 AM
The duplication issue occurs because the kb_category
table lacks a built-in mechanism to identify the language preference of the user who created the record. To resolve this, we can leverage system fields like sys_created_by
to identify the creator and retrieve their profile language. Based on this information, we can adjust the script logic so that if a record is created by a French user, only English (en
) and German (de
) translations are created, and similarly for other languages. This way, we can ensure that unnecessary duplicates are avoided.
also see if you can use gs.getSession().getLanguage() to get the info. Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-25-2024 09:25 PM
Hi @RiyazAhamed ,
Ensure you have the French and German translations available for each Configuration Item name. This can be done by maintaining a mapping table or hardcoding it if the list is small.
Then you can write script to insert record in sys_translated_text table using Asyn business rule.
For example
(function executeRule(current, previous /*null when async*/) {
// Define the translations (This can also be fetched from a custom mapping table or an external source)
var translations = {
"Configuration Item Name 1": {
"fr": "Nom de l'élément de configuration 1",
"de": "Konfigurationselementname 1"
},
"Configuration Item Name 2": {
"fr": "Nom de l'élément de configuration 2",
"de": "Konfigurationselementname 2"
}
};
// Get the name of the newly created KB Category
var categoryName = current.name;
// Check if translations exist for this category name
if (translations[categoryName]) {
// Insert French translation
var frenchTranslation = new GlideRecord('sys_translated_text');
frenchTranslation.initialize();
frenchTranslation.field_name = "name"; // Field to translate
frenchTranslation.table_name = "kb_category"; // Target table
frenchTranslation.locale = "fr"; // French locale
frenchTranslation.document_key = current.sys_id.toString(); // Reference to KB category
frenchTranslation.value = translations[categoryName]["fr"];
frenchTranslation.insert();
// Insert German translation
var grt= new GlideRecord('sys_translated_text');
grt.initialize();
grt.field_name = "name"; // Field to translate
grt.table_name = "kb_category"; // Target table
grt.locale = "de"; // German locale
grt.document_key = current.sys_id.toString(); // Reference to KB category
grt.value = translations[categoryName]["de"];
grt.insert();
}
})(current, previous);
-------------------------------------------------------------------------
If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.
Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay
-------------------------------------------------------------------------