client script showing error on record producer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2024 01:48 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2024 02:34 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2024 02:59 AM
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 mark correct if my response has solved your query.
Cheers,
Mohammed Basheer Ahmed.