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-08-2022 11:26 PM
Hi
In your screenshot this is still in English I believe and not in french language as shown in Red below:
Can you translate this and then try again and see how that behaves
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-08-2022 11:28 PM
Hi
Can you try the solution proposed here in the thread below which talks on the same query as yours :
https://community.servicenow.com/community?id=community_question&sys_id=2d81136ddbdcdbc01dcaf3231f961904
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-09-2022 12:32 AM
Notifications (not when previewing) are executed in the system user's context. Thus the current user is always the system user. Therefore the "current language" will always be the instance default language. That is why the fields are not translated.
In the image below I have used a notification e-mail script that prints the current user's id and user name. As you can see even though the user to make the change to the record is "Developer" and the mail has been sent to that person - the blurred e-mail, in the notification the current user is system:
Thus to solve this, you need to handle translation yourself. That means using notification e-mail scripts. Unfortunately there is no str8 fwd way to do it, it cannot be parameterized, so you pretty much need to create a notification script for each situation (notification), or for each field that you want to include - if you want to reuse that in several notifications.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-09-2022 12:43 AM
I have used the following email script, to get the translated choice label
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',gs.getSession().getLanguage());
gs.info("translation test "+ gs.getSession().getLanguage());
getimpacttranslated.addQuery('value',impactis);
getimpacttranslated.query();
if(getimpacttranslated.next())
{
gs.info("translation test " + getimpacttranslated.label);
template.print(getimpacttranslated.label);
}
}
But in the both the place where i have used gs.info () have returned English as the language and prints the english label for that choice even though the impersonated user is french
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-09-2022 12:56 AM
You need to get the language by loading a user (e.g. Caller in case of Incident) and read the language field. gs.getSession().getLanguage()
still gets you the system user related settings - not usable.