Notification variable not getting translated
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-08-2022 08:00 AM
Hi,
For translation of notifications, we have created notification in each language(french and english). For one of the french notifications, there are variables added in the message body. This notification is created in the sc_request table.
I have changed the language of the recipient to french in the user table and as well as changed the language in profile to french. Look at the image below, the ui is now in french. The field impact's value is translated here.
However when the notification is triggered, you can see the word, 3 -Medium is not translated. The same word is translated as 3 – Modérée in the above image, which is taken from the sc_request table from which the variable is used in the notification record.
How to fix this and translate that variable's value. The translated value is already available in the sys_choice table, but why it does not appear in the notification still remains unclear (language is set to french both in the user table and in the preferences table) .Any workaround/help is appreciated.
Thanks in advance!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-10-2022 07:03 AM
I tried using current.opened_by.preferred_language instead of the global variable(commented out) and got the same result (variable translating). Which one do you suggest? Using two scripts or one script which is down below
var getreq = new GlideRecord('sc_request');
getreq.addQuery('sys_id',current.sys_id);
getreq.query();
if(getreq.next())
{
var impactis = getreq.impact;
var getimpacttranslated = new GlideRecord('sys_choice');
getimpacttranslated.addQuery('element','impact');
getimpacttranslated.addQuery('name','task');
// getimpacttranslated.addQuery('language',u_translationLanguageCode);
getimpacttranslated.addQuery('language',current.opened_by.preferred_language);
// gs.info("translation test "+ u_translationLanguageCode);
getimpacttranslated.addQuery('value',impactis);
getimpacttranslated.query();
if(getimpacttranslated.next())
{
gs.info("translation test " + getimpacttranslated.label);
template.print(getimpacttranslated.label);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-10-2022 09:29 AM
I would use a function to determine the language. If the Opened by user has no language selected, for whatever reason, the returned value will be an empty string. Which will result in label being found. The function has a fallback logic which will allow to get the text not-translated vs. no text at all. In fact you have quite a few options here:
- if this is the single place where you need the language code, you can define the function in this e-mail script and then you don't need no global variable
- if this is the single place where you need the language code and you don't like functions, you can do an if statement
- if this is not the single place where you need the language code, you can define the function in every e-mail script where you need it and use it - no need for global variable
- if this is not the single place where you need the language code and you don't like functions, you can do an if statement in all places where you need the language code
I would for sure go with a function setting a global variable.
The function could be something like:
function u_getTranslationLanguageCode(current) {
return current.opened_by.preferred_language.nil() ? gs.getSession().getLanguage() : current.opened_by.preferred_language + '';
}
and call this in your code as below:
getimpacttranslated.addQuery('language', u_getTranslationLanguageCode(current));
If you prefer ifs, you could write:
if (current.opened_by.preferred_language.nil())
getimpacttranslated.addQuery('language', gs.getSession().getLanguage());
else
getimpacttranslated.addQuery('language', u_getTranslationLanguageCode(current));
Of course assuming that the Opened by user is the one "providing" the language to translate to.
Also if you don't care about data errors and corner cases, you might as well use what you have produced - no function, no global variable.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-25-2022 04:56 AM
have you resolved your issue , i have same issue...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-25-2022 05:24 AM
Yeah, as mentioned above, you need to use notification scripts to translate that variable.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-25-2022 05:33 AM