- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-28-2018 11:42 PM
Hello!
How do I get other current user details (example location, department, phone) in a client script?
Thank you.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-28-2018 11:57 PM
Hi,
Write below code in Display BR
var gr = new GlideRecord('sys_user');
gr.get(gs.getUserID());
g_scratchpad.location = gr.location.name;
g_scratchpad.department = gr.department.name;
g_scratchpad.number = gr.mobile_phone;
Write Below code in onLoad client script
g_form.addInfoMessage(g_scratchpad.location);
g_form.addInfoMessage(g_scratchpad.department);
g_form.addInfoMessage(g_scratchpad.number);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-28-2018 11:44 PM
Hi,
If you talking about the logged in user, I would say that you use a Display Business rule to get the info and put that into the g_scratchpad. then you can reach that scratchpad in the client script.
Here is a good example: Example - retrieve server data using g_scratchpad | ServiceNow Docs

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-28-2018 11:46 PM
Hi
Create a Client Callable Script include :-
var GetUserDetailsAjax = Class.create();
GetUserDetailsAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getInfo: function(){
var obj={};
obj.location='';
obj.email='';
obj.phone='';
obj.street='';
var id=this.getParameter('sysparm_user_id');
var gr= new GlideRecord('sys_user');
if(gr.get(id)){
if(gr.location!='')
obj.location=gr.location.city.toString();
obj.zip=gr.zip.toString();
obj.street=gr.street.toString();
obj.phone=gr.phone.toString();
obj.email=gr.email.toString();
gs.addInfoMessage(gr.location.city);
}
return JSON.stringify(obj);
},
type: 'GetUserDetailsAjax'
});
onChange Client Script :-
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var id = g_form.getValue('u_reference_1');
var ga = new GlideAjax('GetUserDetailsAjax');
ga.addParam('sysparm_name','getInfo');
ga.addParam('sysparm_user_id',id);
ga.getXML(CallBack);
function CallBack(response)
{
var answer = response.responseXML.documentElement.getAttribute("answer");
var user=JSON.parse(answer);
//g_form.setValue('req_email', user.email);
//g_form.setValue('req_phone', user.phone);
//g_form.setValue('address1', user.street);
//g_form.setValue('city_state_zip', user.location);
}
}
Mark Correct if it helps.
Regards,
Omkar Mone.
www.dxsherpa.com

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-28-2018 11:46 PM
Hi,
If you want to achieve by client script then use g_user it will give you all information of user.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-28-2018 11:51 PM
Hi,
If you want to fetch current user data in Client script then you can achieve it by g_user object.And in server side you can fetch by Glide System function.