- 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:28 PM
Hello Runjay,
At least check the sys_translated_text table col names before you paste the script from ChatGPT.