gs.getMessage() not working in email script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-23-2022 03:28 AM
Hello all,
We have a service catalog with a variable that has, say, 2 options. An email script is created to get the translated versions of the drop down options in the email using gs.getMessage(). But even if I change the system language to French and raise the request, and check the email.. the value comes only in English. For some strange reason the translated data doesn't come. In the Messages table, I have an entry for the key and Message(the french text).
Any idea what I might be doing wrong? Below is the code of email script:
var Reqtype = "notification - " + current.variables.request_type.getDisplayValue();
template.print(gs.getMessage(Reqtype));
By the way, the drop-down data for request type comes from another table.. hence getDisplayValue() is used.
Kindly help.
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-23-2022 03:34 AM
Hi,
You need to use gs.getMessageLang() in email script
Please refer https://community.servicenow.com/community?id=community_article&sys_id=fcebed42db8dfc10d58ea345ca961...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-23-2022 03:37 AM
hi.. But I don't have a hard-coded language_id to give as a parameter.. The translation should be dynamic.. depending on the language the request was raised in...
How to determine in which language was the request raised?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-23-2022 04:16 AM
Hi,
Please try below code in email script and create Message in both English and French language
var language;
var template1;
var template2;
var grUser = new GlideRecord('sys_user');
grUser.addQuery('sys_id', current.requested_for); //Replace current.requested_for with your email recipient/event param
grUser.query();
if (grUser.next()) {
language = grUser.preferred_language;
}
if (language == 'en' || language == 'fr') {
// do nothing
}
else{
language = 'en';
}
template1 = gs.getMessageLang("ABC", language); // Replace ABC with your Message Key
template.print(template1);
template2 = gs.getMessageLang("Notification - {0}", language,[current.variables.request_type.getDisplayValue()]);
template.print(template2);