how to get the reference field value and set the value in single line text variable

praveen50
Tera Contributor

how to get the reference field value and set that value in single line text variable.

 

I have catalog item under that i have

 

Requested by--

On behalf of - here i have two choices -me,on behalf-if suppose end user will select on behalf option he will change the requested by details that time pick that value set in -"on behalf of person"

on behalf of person--

 

i have catalog client script for on change

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if(window == null){
var behalf = g_form.getDisplayBox('substantiation_requested_by_ref');

var user = behalf;

g_form.setValue('substantiation_name_of_the_person_this_is_on_behalf_of_stxt',user)

}
else{
var behalf = g_form.getDisplayBox('substantiation_requested_by_ref').value;

var user = behalf;

g_form.setValue('substantiation_name_of_the_person_this_is_on_behalf_of_stxt',user);
}

//Type appropriate comment here, and begin script below

}

 

am not getting the value

 

 

find_real_file.png

 

if change the script below like only  native ui is working ,portal is getting java script browser console error.

 

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

var behalf = g_form.getDisplayBox('substantiation_requested_by_ref').value;

var user = behalf;

g_form.setValue('substantiation_name_of_the_person_this_is_on_behalf_of_stxt',user);

//Type appropriate comment here, and begin script below

}

 

can you help any one 

1 ACCEPTED SOLUTION

Hi,

something like this

1) Ensure Isolate Script field is set to false for your client script

2) This field is not on form but from list you can make it false

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

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


	var behalf;
	if(window != null){
		behalf = g_form.getDisplayBox('substantiation_requested_by_ref').value;
	}
	else{
		behalf = g_form.getDisplayValue('substantiation_requested_by_ref');
	}

	g_form.setValue('substantiation_name_of_the_person_this_is_on_behalf_of_stxt', behalf);

	//Type appropriate comment here, and begin script below

}

find_real_file.png

regards
Ankur

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

View solution in original post

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

there is different syntax to get display value in portal

I have created blog for that to get it in Native + Portal

Get Display value of reference variable Service Catalog

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

Regards
Ankur

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

Hi,

something like this

1) Ensure Isolate Script field is set to false for your client script

2) This field is not on form but from list you can make it false

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

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


	var behalf;
	if(window != null){
		behalf = g_form.getDisplayBox('substantiation_requested_by_ref').value;
	}
	else{
		behalf = g_form.getDisplayValue('substantiation_requested_by_ref');
	}

	g_form.setValue('substantiation_name_of_the_person_this_is_on_behalf_of_stxt', behalf);

	//Type appropriate comment here, and begin script below

}

find_real_file.png

regards
Ankur

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