Show fields for a user based on his preferred system language

rafas_2703
Tera Guru

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 🙂

1 ACCEPTED SOLUTION

Mehta
Kilo Sage
Kilo Sage

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);
 },

 

View solution in original post

5 REPLIES 5

Sandeep Rajput
Tera Patron
Tera Patron

@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.

 

 

But how can I add that condition to a UI Policy? It isn't possible or is it?

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.

Mehta
Kilo Sage
Kilo Sage

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);
 },