g_form.DisplayBox('') is not working in the portal

Rama Rao
Tera Contributor

Hi All,

Actually, I need to get the value of the reference field. So I am using 'g_form.DisplayBox('')' but it not working in the portal and gives a javascript console error.

Can anyone help me with that?

Note: The field refers to the Service offering table and I need to auto-populate the service offering name in another field.

7 REPLIES 7

Ankita19
Tera Guru
Tera Guru

You can use catalog client script and client callable script include to achieve your requirement.

and use g_form. getDisplayValue(); in your client script for reference only fields.

Murthy Ch
Giga Sage

Hi @Rama Rao 

Use 

g_form.getDisplayValue("variable_name");  //but not recommended

Thanks,

Murthy

Thanks,
Murthy

Ankur Bawiskar
Tera Patron
Tera Patron

@Rama Rao 

I had written blog for this 2 years ago and it works in both Native + Portal

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

Get Display value of reference variable Service Catalog

Sharing the solution here as well

1) For portal -> getDisplayValue()

2) For native -> getDisplayBox()

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