- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2019 07:57 PM
Hi all,
I need to autopopulate the mobile number field from the sys_user table on the catalog item:
I am using javascript:gs.getUser().getRecord().getDisplayValue("mobile_phone"); in the default value tab of the variable "Contact Number" to get this autopopulated, but it does not, any suggestions?
I do not need change this field through onChange or any Catalog client scripts as I am leaving this field open anyway for them to change the contact number if they want to (because for example: changed phone number but not updated on sys_user record).
Thanks.
Solved! Go to Solution.
- Labels:
-
Personal Developer Instance

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2019 09:05 PM
there's a gs.getUser() method for it, so you could use the following directly in the default value of the field or variable:
javascript: var userPhone; var user = new GlideRecord('sys_user'); if (user.get(gs.getUserID())) {userPhone = user.phone}; userPhone;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2019 08:02 PM
Can you try logout and login again. I guess gs.getUser().getRecord() is cached at login.
Try with getValue once
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2019 08:29 PM
logout and login - still same, it does not populate the number in the catalog field automatically.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2019 08:13 PM
Hi,
For Auto population of the above deabove-definedes 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.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2019 08:33 PM
Hi Ram,
Thanks for sharing the script, however, as i mentioned I am reluctant to use this long piece of codes where we could do this in one line for example I am autopopulating the caller manager with javascript: gs.getUser().getManagerID(); and it works perfect, so there should be a way to populate the phone number similar to this. I will keep looking.