- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-31-2018 03:10 PM
Hi everyone,
I need to get the company's name from the next code, but actually im getting the company sys_id, anyone can help me getting the dusplay name or the name to populate a text field??
------------------------------------------------------------------------
function onChange(control, oldValue, newValue, isLoading) {
var id = g_form.getValue('user_sol');
var user = new GlideRecord('sys_user');
user.addQuery('sys_id',id);
user.query();
if (user.get(newValue)){
g_form.setValue('Prueba_cargo',user.title);
g_form.setValue('area_sol',user.core_company);
}
}
----------------------------------------------
thanks in advance
Solved! Go to Solution.
- Labels:
-
Personal Developer Instance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-01-2018 03:19 AM
Hi,
Try with below code,
In Client script
var ga = new GlideAjax("UserCompany");
ga.addParam("sysparm_name","userCompany");
ga.addParam("sysparm_user",g_form.getValue('user_sol'));
var company = ga.getAnswer();
g_form.setValue('area_sol',company);
In Script Include
var UserCompany = Class.create();
UserCompany.prototype = Object.extendsObject(AbstractAjaxProcessor, {
userCompany: function() {
var company='';
var user= this.getParameter("sysparm_user");
var comp = new GlideRecord('sys_user');
comp.addQuery('sys_id',user);
comp.query();
if(comp.next())
{
company=comp.getDisplayValue('company');
}
return company;
},
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-31-2018 03:40 PM
I think this is a duplicate post to the below one
https://community.servicenow.com/community?id=community_question&sys_id=9cad99ebdbde9b043882fb651f961944
Hope my response in the above link helps you.
Please hit correct based on impact of response.
Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-31-2018 03:44 PM
Hello Hapuertam,
The best practice is to use GlideAjax instead of GlideRecord in the client script. You can use getDisplayValue() on the server side and return it back to a client.
https://community.servicenow.com/community?id=community_blog&sys_id=f8ccee25dbd0dbc01dcaf3231f961978
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-01-2018 02:50 AM
Hi,
Refer below code...
script Include : requestor_details
onLoad Cleint script :
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-01-2018 02:57 AM
You can use the below to get the display value from a reference field in a client script but, as has been mentioned, you shouldn't use getReference() or glide records in the client.
g_form.getDisplayBox('field_name').value;