unable to fetch value with getDisplayvalue command
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-21-2017 06:21 AM
Hi ,
i am trying to fetch open on behalf of user Region value (service catalog form ) and i use the below script , i tried with getDisplayValue() and get value() also , both are not working- can someone please correct/suggest me -Region field is of "String type" in cmn_localtion table
function onChange(control, oldValue, newValue, isLoading) {
var caller = g_form.getReference('open_on_behalf_of', getValue);
function getValue(caller)
{
var k1=caller.location;
alert(k1); //getting Sys_id here
var k=new GlideRecord('cmn_location');
k.addQuery('sys_id',k1);
k.query();
alert(k); //getting object from table here ******i used below commands to get Region value
var k2 = k.getValue('u_region');
var k2 =k.u_region.getDisplayValue();
alert(k2);
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-21-2017 06:48 AM
Hi Durgaprasad,
You missed adding the
while(k.next()){
}
Please use below script and try
function onChange(control, oldValue, newValue, isLoading) {
var caller = g_form.getReference('open_on_behalf_of', getValue);
function getValue(caller)
{
var k1=caller.location;
alert(k1); //getting Sys_id here
var k=new GlideRecord('cmn_location');
k.addQuery('sys_id',k1);
k.query();
alert(k); //getting object from table here ******i used below commands to get Region value
while(k.next()){
var k2 = k.getValue('u_region');
var k2 =k.u_region.getDisplayValue();
alert(k2);
}
Please mark the response correct/helpful based on the impact.
Thanks
Gaurav

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-21-2017 07:04 AM
Hi,
Try this:
var k=new GlideRecord('cmn_location');
k.get(k1);
var k2 = k.u_region.name;// or u_name based on field name
alert(k2);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-21-2017 07:57 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-21-2017 08:06 AM
Hi Durgaprasad,
Use the below script, It is working fine. check the screenshot attached.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var caller = g_form.getReference('caller');
var k1 = caller.location;
var k = new GlideRecord('cmn_location');
k.addQuery('sys_id', k1);
k.query();
var location_obj = k.rows[0];
for (var x in location_obj) {
if (location_obj[x].name === 'name') {
alert(location_obj[x].value);
return;
}
}
}
check the location_obj value in the console as well to get a fair idea.
Mark this as correct answer, If this helps in solving your use-case.
Thanks,
Shivam