How to get display value of a reference field in catalog client script (in service portal)

Gopi22
Giga Guru

Hi,

We are using a reference field - 'requester' in the catalog form which reference to sys_user table. 

We need to get the display value of this field in catalog client script for building some functionality. 

I tried various methods suggested in community - like g_form.getDisplayValue(), g_form.getDisplayBox(), etc but nothing seems to be working fine.

Please let me know if there is a way to do this.

Thanks,

Gopi

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

I have written blog for this and it works in native + portal

Get Display value of reference variable Service Catalog

If my blog helps please mark it helpful and also bookmark it

sharing the script here as well

Note: The solution requires this Isolate Script field as false considering the window object in script being used

Example: my variable "requester" is reference to sys_user table

function onChange(control, oldValue, newValue, isLoading) {
	if (isLoading || newValue == '') {
		return;
	}
	if(window == null){
		var valuePortal = g_form.getDisplayValue('requester');
		alert('Portal->' + valuePortal);
	}
	else{
		var valueNative = g_form.getDisplayBox('requester').value;	
		alert('Native->' + valueNative);
	}
	//Type appropriate comment here, and begin script below
}

image

Output:

Native:

image

Portal:

image

 

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

8 REPLIES 8

Please share complete script and client script configuration screenshot

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur,

PFB script. I need the display value when the value of rsa = 'Yes'

 

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}

var rsa = newValue;
if (rsa == 'no') {
top.window.open(url, '_blank');
} else {
if (window == null) {
var valuePortal = g_form.getDisplayValue('who_s_this_request_for');
alert('Portal->' + valuePortal);
} else {
var valueNative = g_form.getDisplayBox('who_s_this_request_for').value;
alert('Native->' + valueNative);
}
}
}

 

Thanks,

Gopi

Hi,

Did you ensure Isolate Script is set to False for this client script

the blog I created has worked for many members.

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur,

It seems your solution was working after all.

The reason it was not working at first might be because I was utilizing a multi row variable set and with your script I was trying to get the display value of a reference field which was not part of the multi row variable set. 

The script seems to be working when I am trying to get the display value of a reference field which is part of the multi row variable set. 

So I guess, since I am using g_form, it only takes in the value from the current form which is different in case of multi row variable set.

But one thing I noticed was that the Isolate Script functionality does not have any impact. The script seems to be working even if the value of Isolate Script is set to true.

 

Also, on another note, I have another solution for this scenario that is to use getReference(). Which solution do you recommend ? 

 

Thanks,

Gopi