getDisplayValue() not working in a catalog client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2014 10:51 PM
We are currently on Dublin patch3 and I am trying to set up a catalog client script where when a 'requested for' person is chosen I want to write some of the information from the user record to read only variables. The problem it seems is that the getDisplayValue() for a reference field on the user record, like manager, does not seem to work.
Here is my catalog client script -
var rq4 = g_form.getValue('requested_for');
// alert('The req for id is ' + rq4);
var gr = new GlideRecord("sys_user");
gr.addQuery("sys_id", rq4);
gr.query();
if (gr.next()) {
var mgr = gr.manager.getDisplayValue();
//alert (mgr);
g_form.setValue('v_current_mgr', mgr);
g_form.setReadOnly('v_current_mgr', true);
If I remove the 'getDisplayValue from the mgr variable then the sys_id of that manager field will be displayed but I want the name. Other than doing another GlideRecord on the manager does anyone have an idea on why this would not work? I can use this code in a backgroup sript and I get the manager name ok. Just wondering if anyone else has run into this issue.
- Labels:
-
Service Mapping
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2014 11:25 PM
Client GlideRecord object does not support getDisplayValue() function... It would only be supported when it runs on gliderecord object at server side.
So would suggest, write up a script include to return the display value of manager for the corresponding user.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2014 11:57 PM
you can use the below script
var rq4 = g_form.getReference('requested_for');
g_form.setValue('v_current_mgr',rq4.manager);
I suppose that your v_current_mgr variable is a reference field to sys_user table. The script which I have mentioned above is not a best practice according to service now.
The best possible way is to initiate a GlideAjax call on your client script, and plac eyour GlideRecord query into a script include.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2014 12:22 AM
Hi Matthew,
It is recommended to use Callback function with the getReference function.
Refer to the following Wiki Link:-
GlideForm (g form) - ServiceNow Wiki
Thanks,
Subhajit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2014 12:30 AM
You can use the DOT walking, see: Dot-Walking - ServiceNow Wiki