- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2019 07:35 PM
I set "javascript:gs.getUser().getCompanyID()" in the Default Value field to automatically populate company name of logged in user into a table form, however, the result shows sys_id of the company name...
I would like to get just company name (NOT sys_id), so could someone tell me how to fix the script?
Best Regards,
Aki
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2019 08:04 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2019 07:40 PM
Hi,
Make this field as a reference type or instate of ID get company name.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2019 08:04 PM
Try this
javascript:gs.getUser().getCompanyRecord().name
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2019 08:05 PM
Hello,
First of all you have to make your variable as reference type and reference Company table .
Second one you have to create Script include and call in default value in variable.
Refer below link for more information and code.
Please mark as correct and helpful,If you get any help worthy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2019 09:09 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("company", user_detail.company);
}
},
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("company");
var user = result[0].getAttribute("user");
g_form.setValue('requestor_company',company);
g_form.setValue('requestor_name',user);
}
}
type: 'requestor_details'
});
Hope this helps.Mark the answer as correct/helpful based on impact.