- 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
‎04-04-2017 07:06 AM
Hi Tiyasa,
This can be done. It will require a client script watching for changes on the Requested For field and then go to the server to retrieve all the details and populate them in to the various fields. This can be a bit of a maintenance headache as people request fields added/removed.
I'm going to recommend against putting a bunch of related fields on the form as a bad practice. Most of this information is available simply by hovering over the "i" icon next to the reference field. Unless you anticipate the user changing their department, customer unit, or something else during the request process (which isn't likely for most of this information) then I would leave it off the form. It's what reference fields were designed to do.
After all, who likes a form with lots of fields? Not me that's for sure. I want to get in, get out, get on to the next thing.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-04-2017 08:00 AM
Hi Chuck,
That is indeed a very valuable lesson I learned. I was blindly just implementing every requirement that I got without thinking about efficient and good programming. I am going to suggest back and see what is the outcome. However, just for my knowledge, if I need to implement this,I need a combination of script include & onload client script if I read you correctly?
Thanks,
~T

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-04-2017 10:23 AM
Yes, if you HAD to do at least one or more of these fields, then GlideAjax is going to be the way to go. See episode 33 here for a good example how to pass back a lot of information in one call from the client to the server using a JSON object.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-31-2018 07:39 AM
Hello Chuck,
I have a requirement where i need to show on a catalog item, the information of a Requestor. Suppose i am requesting an item then on "requested by" field it should show my name and off course the details of mine will be shown on a reference. But the problem i have is, once i checkout my request and a RITM is created and then if i impersonate as another user and check the RITM, the requested by is showing up the impersonated user name. Which should not be. Is there anyway to setup as i want from OOB? Or how to achieve this?