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

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

Hi Ankur,

Thank you for your update. 

I had already tried the method you mentioned in your blog. Awesome blog btw !!

It seems to be working fine if the the OnChange catalog client script is running on change of the variable value of the concerned reference field. 

But my scenario is, I have a Yes/No field, selecting the value as 'Yes' should get me the display value of the Requested User (reference field to sys_user table). So the OnChange script runs on change of the Yes/No variable.

I believe I need to use either getReference method or a GlideAjax for this scenario. Please suggest your thoughts.

Thanks,

Gopi

Hi,

let the script run on change of any variable the syntax and logic remains the same

so it should work fine

Regards
Ankur

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

Hi Ankur,

For some reason, it is showing empty. 

g_form.getDisplayValue() is returning null.

 

Thanks,

Gopi