- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-04-2017 07:02 AM
Hello everyone,
So I need to auto fill User information based on the current logged in User. I did search the community and found loads of suggestions but mostly
when a user is selected and the related other fields are populated.
I tried to set the following values to Default for the variables but most did not work
- Requested For : javascript:gs.getUserName(); Worked fine.
- Phone Number : javascript:gs.getMobileNumber();
- Company : javascript:gs.getUser().getCompanyID();
- Location : javascript:gs.getUser().getLocation(); Returns a value but per the user record of the current logged in user, the value returned is Country not Location.
- Department :
- Division :
- BU:
- CU:
- Cost Center :
Additionally, I did try to create a catalog client script on load and fetch the object of the user record, but it doesn't work too.
Thank you ,
Tiyasa
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-04-2017 12:01 PM
Hi,
For Auto population of the above defined Variables you can write an Script Include and call the same Script Include in an OnLoad Catalog Client Script as mentioned below:
Script Include:
var requestor_details = Class.create();
requestor_details.prototype = Object.extendsObject(AbstractAjaxProcessor, {
requestor_info: function() {
var result = this.newItem("result");
var logged_user = gs.getUserID();
var user_detail = new GlideRecord('sys_user');
user_detail.addQuery('sys_id',logged_user);
user_detail.query();
while(user_detail.next())
{
result.setAttribute("user",user_detail.sys_id);
result.setAttribute("phone", user_detail.phone);
result.setAttribute("email",user_detail.email);
result.setAttribute("location",user_detail.location);
}
},
type: 'requestor_details'
});
2) Then you can write an On Load Catalog Client Script wither on your Catalog Item or on the Variable Set to have the variables populated as shown below:
Script:
function onLoad()
{
var ga = new GlideAjax("requestor_details");
ga.addParam("sysparm_name","requestor_info");
ga.getXML(ajaxResponse);
function ajaxResponse(serverResponse) {
var result = serverResponse.responseXML.getElementsByTagName("result");
var phone = result[0].getAttribute("phone");
var user = result[0].getAttribute("user");
var email = result[0].getAttribute("email");
var loc = result[0].getAttribute("location");
g_form.setValue('requestor_phone',phone);
g_form.setValue('requestor_name',user);
g_form.setValue('Location_user',loc);
}
}
Replace your Variable Name appropriately in the Set Value Conditions say for example in place of the variable "Location_user" with your Location Variable.
In a Similar Way you can try for other Variables also.
Hope this helps.Mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-04-2018 05:00 AM
If I understand right...
- You impersonate a user
- You fill in the form
- You use YOUR name in Requested By
- You submit/save
- The impersonated name shows up in the details
Is that correct?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-04-2018 10:28 AM
No Chuck, let me explain,
Suppose i am an end user and want to submit a new catalog item request in which i will see my name under "Requested by" field and then filled the form and Ordered and checked out. Now i will impersonate you and i will check the request that i have submitted. Then when i open the RITM and see at the variables, the "Requested by" is now showing your name instead of my name.
I found the solution for this,
just in the "Requested by" variable, i need to setup the default value to "javascript:gs.getUserID();" and it worked as expected.
Mark if this solution is correct.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-05-2018 05:06 AM
This feels like a "corner case" used only in testing and not a production issue. People aren't actually impersonating other people in production are they? If so, I would advise against that as a general practice.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-04-2017 07:23 AM
Hi Tiyasa,
Please refer GlideSystem API. we dont have methods like gs.getMobileNumber();
You can use onload catalog client script for this requirement. And use getReference(fieldName, callback) method to read user data like mobile no, city.,, etc.
GlideForm (g form) - ServiceNow Wiki
- Giri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-04-2017 07:46 AM
Hello Giri,
I referred to Getting a User Object - ServiceNow Wiki which mentions in section "Descriptive Functions" about fetching such information. Maybe, I got the idea of implementing wrong?
I will try to fix my client script to see if I can achieve what I need.
Thanks,
~T