onChange Catalog Client Script to display a value

Julia Howells
Giga Guru

I have a catalog item that references the cmn_location table. When the user selects a location, I do not want it to display the location name, but the site code [u_site_code] on the form. How can this be achieved? 

4 REPLIES 4

Vasu ch
Kilo Sage

Hi @Julia Howells 

You can write the below onChange catalog client script:

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }
	var ref = g_form.getReference("location", callback);  // Replace location with your variable name
	function callback(loc){
		g_form.setValue("location",loc.sys_id,loc.u_site_code);   // Replace location with your variable name
	}
}

 

Normally, if we want change the display value of a reference field, we have to set Display=true in the field at the table level. But this change is global. So choose the solution as per your need.

 

Regards,

Vasu Ch

Harsh_Deep
Giga Sage
Giga Sage

Hello @Julia Howells 

 

You can use select box as a type of variable then there you can choose the field value which you want to show in the dropdown.

 

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.

mads2
Tera Contributor

Be aware the lookup select box are very heavy on performance. It is not recommended to use select box unless there is a query ensuring it returns very few records. Even though it is much slower than a reference type variable.

ersureshbe
Giga Sage
Giga Sage

Hi, I recommend to use 'lookup select box' field type to achieve it.

Regards,
Suresh.