- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-13-2016 06:39 AM
Hi everyone,
I am writing a client script in record producer to auto-fill a few user info fields based on the requester name (Your_name) entered. (The requester field is NOT a reference field)
I managed to write something below to find the requester name in user table and get the value for email, company and location :
My problem is the company and location fields in user table are reference field so they returned sys id...
I tried using gr.getDisplayValue but it doesn't seem to work in client script...
Can anyone suggest a way to get the display value for those two fields so I can auto-populate them in actual names not in sys id?
(It's returning like below now...)
Thank you!
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-13-2016 06:42 AM
I recommend doing this with an Ajax call. You need more than just the user's information in this case. Using a GlideRecord query or getReference() will work, but you'll have to make multiple calls. GlideAjax (and the corresponding server side script include) can be more surgical.
Hint: return a JSON object with sys_id and display value and use three arguments for your g_form.setValue() otherwise, you're wasting another return trip to get the display values.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-13-2016 06:43 AM
You cant use getDisplayValue() function in client script.
You need to use getDisplayBox() function.
Please go through below threads.
Please go through below threads.
Re: getValue on a reference field
Re: catalog client script onsubmit
Thanks,
Mihir
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-13-2016 07:03 AM
Use Ajax call for this :-
example code..
var SetDepartment = Class.create();
SetDepartment.prototype =
Object.extendsObject(AbstractAjaxProcessor, {
CallerDeptDetails: function() {
var caller =this.getParameter('sysparm_user_caller');
var callerDetails = new GlideRecord('sys_user');
callerDetails.addQuery('sys_id',caller);
callerDetails.query();
if(callerDetails.next())
{
dept = callerDetails.department.name;
}
return dept;
},
});
Mark Correct if it solved your issue or hit Like and Helpful if you find my response worthy.
Thanks,
Deepa
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-20-2023 06:18 AM
Hi,
with the field Isolate script set to false on the client script form you can get the display value like this:
document.getElementById("sys_display." + g_form.getElement('field_name').id).value;
Hope it helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-20-2023 06:44 AM
Don't touch isolate script, let it be at its default value.
Use the below to get the display value of reference field
g_form.getDisplayBox('<field name>').value