client script showing error on record producer

rmaroti
Tera Contributor

Hi Everyone,

I have requirement logged in user country should be map on "Country" variable which is single line text  on record producer but im getting the sys id of logged in user not getting logged in user country name.

 

please see below screen shot.

 

please let me know what i need to change.

 

11 REPLIES 11

Aniket Chavan
Tera Sage
Tera Sage

Hello @rmaroti ,

You can give a try to the modified script include below.

var LoggedInUserCountry = Class.create();
LoggedInUserCountry.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {

    getCountry: function () {
        var details = this.getParameter('sysparm_user_name');
        var usr = new GlideRecord('sys_user');
        usr.addQuery('sys_id', details);
        usr.query();

        if (usr.next()) {
            var country = usr.location.country + '';
            return country;
        }

        return null;
    }
});

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks,

Aniket

 

 

Basheer
Mega Sage

Hi @rmaroti 

Below are the things which you need to do

In Client Script

function getResponse(response) {  
   var coe= response.responseXML.documentElement.getAttribute("answer"); 
    alert(coe);
if(coe){
g_form.setValue("country",coe);
}
}

 

In Script Include

var country = ""; //We need to declare the country outside

Your code of gliderecord

if(usr.next()){
country = usr.location.country;
}
return country;


Please mark this as answered, if this solved your problem.

Please mark helpful, if this has helped you in any ways 

Please hit like button if my suggestion has helped you in any way.
Please mark correct if my response has solved your query.

Cheers,
Mohammed Basheer Ahmed.