How to change system language in script

peter_repan
Tera Guru

Hi all,

we have several languages in our instance.

During the processing of the workflow, we have some business logic which is sending data to third party system.

Time of sending can be various, it depends on some triggers in the system.

Data must be always in German.

Is it possible to change system language to German in script?

I know that one possible approach is to impersonate as some German speaking user:

gs.getSession().impersonate(current.variables.<USER_VAR>.sys_id);

but this approach is not desired since it creates dependency on certain user and we cannot rely on it.

I have also tried code like:

var session = new GlideSession();

session.setLanguage('de');

but it is not working.

We are currently living with our own translation scripts - which are searching in sys_translated_text table for translations.

I was just wondering if there is another (better) way how to get German translations.

I expect some code which only changes language for current session or for current script and then it switches language back to previous.

Any ideas?

7 REPLIES 7

Hello Christina,



In my case, I wanted to force an import to execute in French (even though logged user is using English) and I used your code in my onStart Transform Script.


It worked.



Thanks


Jim Coyne
Kilo Patron

Has there been any improvement in how this works?

I need to create some Notifications and export some documents to HTML/PDF and require the French translations of certain fields when creating the French versions of the Notifications or documents.

You'd think there would be a GlideElement method that takes a language parameter to return what we need - the translated text or the original text if no translation exist.

Ritika Saran
Giga Contributor

Hello everyone,

 

I'm trying below script on script action which is triggered from an event in sn_hr_va scope.

 

**** script****

var util = new I18nUtils();


util.setLanguage('es')

 

**********

 

However, the script doesn't works. But if I use the same script on background scripts then it updates user preference record. Kindly assist.

 

@Ankur Bawiskar  Please assist.