- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2023 01:46 AM
Hi,
I'm created a record producer with some variables but I wanted some of those variables to be accessible depending on the user preferred language.
For example variables A,B,C should only appear if user's preferred language is English and variables D,E,F should only appear if user's preferred language is Dutch,
How can I do that?
Thank you 🙂
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2023 05:11 AM
You can have a onchange client script which will be calling glide ajax and after parsing the response, you can hide/show the fields depending on the users language. In order to do that you need to check user preference for user's selected language.
Below is the sample client script code :
var user = g_form.getValue('user'); // user variable
var ajax = new GlideAjax('userlanguage');
ajax.addParam('sysparm_name', 'getUserDetails'); // function name
ajax.addParam('sysparm_user', user); // user
ajax.getXML(userParse); // call back function
function userParse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
var users = JSON.parse(answer); // parse response
if(users[0].language == "en")
{
g_form.setVisible('priority', false);
}
}
Script Include :
getUserDetails: function() {
var details = [];
var user = this.getParameter('sysparm_user');
var userPref = new GlideRecord("sys_user_preference");
userPref.addQuery("user", user);
userPref.addQuery("name", 'user.language');
userPref.query();
if (userPref.next()) {
var users = {};
users.language= userPref.value;
details.push(users);
}
return JSON.stringify(details);
},

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2023 04:45 AM - edited 04-19-2023 04:46 AM
@rafas_2703 best way is to create a UI Policy and add a condition e.g. preferred_language = English
check Reverse if false.
In the UI Policy Actions, set those fields to Visible true which would would like to show for English Language and Set Visible False for those variables which you would like to hide for English language. Also, make sure to check on Load check box for this UI Policy.
Since Reverse False is already checked, no separate handling would be needed for the Dutch language.
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2023 06:47 AM
But how can I add that condition to a UI Policy? It isn't possible or is it?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2023 07:00 AM
If you have a preferred language as a variable on the catalog item or record producer then you can add it into the UI Policy condition. If you don't then pick the user's preferred language from the system preference and set it on a variable on the catalog item/record producer and hide this variable using a onLoad client script. Rest of the steps can be configured using the response shared earlier.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2023 05:11 AM
You can have a onchange client script which will be calling glide ajax and after parsing the response, you can hide/show the fields depending on the users language. In order to do that you need to check user preference for user's selected language.
Below is the sample client script code :
var user = g_form.getValue('user'); // user variable
var ajax = new GlideAjax('userlanguage');
ajax.addParam('sysparm_name', 'getUserDetails'); // function name
ajax.addParam('sysparm_user', user); // user
ajax.getXML(userParse); // call back function
function userParse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
var users = JSON.parse(answer); // parse response
if(users[0].language == "en")
{
g_form.setVisible('priority', false);
}
}
Script Include :
getUserDetails: function() {
var details = [];
var user = this.getParameter('sysparm_user');
var userPref = new GlideRecord("sys_user_preference");
userPref.addQuery("user", user);
userPref.addQuery("name", 'user.language');
userPref.query();
if (userPref.next()) {
var users = {};
users.language= userPref.value;
details.push(users);
}
return JSON.stringify(details);
},