- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2020 02:10 PM
Hi Experts, our team is completely new to Virtual Agent and have a few questions regarding localization. One of the first questions we want our Virtual Agent to ask is for the user to select their preferred language. From there we have a Decision Utility that splits off into all the languages we want to incorporate. Once a user selects Spanish for example, we would like all of the subsequent questions and selections to translate to Spanish. To test this, we currently have a Bot Response - Script Output that looks like this:
In the Messages table, we created the following entry:
When previewing and choosing Spanish, the Virtual Agent still responds in English:
Are we missing any steps to have this return "Hola David!" instead? Additionally, if we wanted all subsequent questions to be in Spanish, what steps would we need to take to achieve this? If one of the languages we want to incorporate is not available as a plugin, is it possible to translate as well?
Any guidance on this is greatly appreciated.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2020 07:19 AM
Can you try changing the language under the user settings? Instead of the preferred language field on the user record?
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP
---
LinkedIn
Community article list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2020 07:17 AM
Hi there,
If you have the Spanish language plugin, and users have actually set Spanish as their language, then I don't really see why you want what you described? Selecting a language within the Virtual Agent.
Can you functionally describe what you are really after? Indeed like you answered yourself already:
"If that's the case, then having VA ask what their preferred language is as the first question seems pointless."
I mean, if a user has Spanish selected, then UI Messages, Translated Name / Fields, etc, etc are applied. Also for Virtual Agent. So the Virtual Agent web client will be translated already. And for all topics (out-of-the-box more than 90% covered) will already be translated is UI Messages have been set up.
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP
---
LinkedIn
Community article list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2020 11:41 AM
Hi
Here's what we have so far:
Our code for the Change Language Script Action is as follows:
(function execute() {
var lang = gs.getSession().getLanguage();
gs.info('my langauge is: ' + lang);
//lang != 'es' ? true : false;
if(lang!='es'){
//return true;
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id',gs.getUserID());
gr.query();
if(gr.next()){
gr.preferred_language = 'es';
gr.update();
}
} else {
return;
}
})()
The following Greeting in Spanish looks like this:
return gs.getMessage('Hello, {0}', [vaInputs.user.first_name]);
However, when we preview, the Spanish Greeting never gets translated.
Any thoughts? Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2020 11:54 AM
So is the preferred_language really updated, did you validate that? I would suspect, a refresh of the browser would be necessary. And that's not the case here.
I did mention before already, consider using gs.getMessageLang(). Unfortunately, then you would need to script every message, though works fine for your requirement. Sure it's more work, though you also don't have a real standard requirement 🙂
For example, below code would give me the UI Message "Show me everything", in Dutch. Independent of the actual preferred_language. So it would show the Dutch UI Message, even if the user has preferred language English.
gs.getMessageLang('Show Me Everything', 'nl')
Guess for Spanish this would be "es". Test it out, and then make it dynamic.
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP
---
LinkedIn
Community article list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2020 12:42 PM
Got it! I just tried:
return gs.getMessageLang('Hello, {0}', 'es', [vaInputs.user.first_name]);
and it translated it correctly to Hola: David!
Just so I'm understanding this correctly, if our team uses gs.getMessage, that is dependent on the user's preferred_language on sys_user to be in Spanish. Is this correct?
gs.getMessageLang will allow messages to translate to Spanish without the preferred language on sys_user to change at all, but it will require us to translate all of our phrases and save them to System UI - Messages table.
If we wanted everything after a user selects Spanish to appear in Spanish, how would we translate the text in the red box below?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2020 12:53 PM
You will for sure not be able to have EVERYTHING translated this way. Some sentences which are shown in topics, are actually not part of topics, though part of the Virtual Agent web client. These you can only influence with the UI Messages. So you will not cover 100%. Be aware of that.
Also indeed you do need to script all your messages, all your choices. That will be quite a bit of work. Or actually, static choices are no option with your requirement... you can't script these. You could mimic the choices though, with use of a scripted Reference Choice instead.
Example code which is displayed in the Reference Choice:
var options = [];
options.push({ 'value': 'best_italian_1', 'label': gs.getMessage('Best Italian Restaurant Ever'), 'render_style': 'data' });
options.push({ 'value': 'best_italian_2', 'label': gs.getMessage('Even Better Italian Restaurant'), 'render_style': 'data' });
return options;
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP
---
LinkedIn
Community article list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field