Autopopulate field on the basis of user language

Nisha Mishra23
Tera Contributor

Hello everyone 

 

I want to auto populate one field on catalog item form on language bases . For example I have one variable name country which have 4 option us,uk ,Netherlands and others. I want to auto populate Netherlands if user is from Netherlands

1 REPLY 1

Runjay Patel
Giga Sage

Hi @Nisha Mishra23 ,

 

Use if from which country are you identifying based on their language, how? or User's location's Country?

 

You can write onchange catalog client script and call script include to get the country which user belong to and then in client script set the country.

 

Cline script code

If country value are different in catalog variable from user country then you have to do check like if (answer=='USA') answer ='us'.

    var ga = new GlideAjax('AjaxUtils');
    ga.addParam('sysparm_name', 'returnUserCountry');
    ga.addParam('sysparm_sys_id', 'pass sys_id of your user');
    ga.getXML(setCountry);

function showMessage(setCountry) {
    var answer = response.responseXML.documentElement.getAttribute("answer");
    g_form.setValue('u_country' , answer );
}

 

Script include code

var AjaxUtils = Class.create();
AjaxUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    returnUserCountry: function() {
        var country='';
        var sysId = this.getParameter('sysparm_sys_id');
        var gr= new GlideRecord("sys_user");
        gr.addQuery('sys_id', sysId);
        gr.query();
        if (gr.next()) {
            country = gr.location.country;
        }
        return country;
    },
    type: 'AjaxUtils'
});

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

-------------------------------------------------------------------------