Can't get g_form.setLabelOf to work

Daniel103
Giga Contributor

I'm trying to use g_form.setLabelOf in an onChange client script on the default Problem form. Here is my very simple code:

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

	if(newValue == 'software'){
		g_form.setLabelOf('short_description', 'Problem Statement');
		g_form.setLabelOf('description', 'What is current state?');
		g_form.showFieldMsg('short_description', 'should have changed to PS', 'info');
	}
	else{
		g_form.setLabelOf('short_description', 'still Short description');
		g_form.setLabelOf('description', 'still Description');
		g_form.showFieldMsg('short_description', 'should have changed to SD', 'info');
	}
}

The field is the OOB "category" field. The showFieldMsg calls are just to check that the code is making it to those points, which it is. None of the setLabelOf calls work. When I run setLabelOf in my browser console it also doesn't work and returns false. If I put a nonexistent field into the fieldname variable of setLabelOf then I get an error field-message: 

onChange script error: TypeError: Cannot read property 'id' of undefined function () { [native code] }

Am I doing something wrong? Shouldn't setLabelOf work dynamically without saving or reloading the form?

 

1 ACCEPTED SOLUTION

Daniel103
Giga Contributor

Figured it out, the issue is caused by the SN Utils browser plugin. setLabelOf doesn't change the labels dynamically when the SN Util "Show Technical names on page load" setting is on.

View solution in original post

14 REPLIES 14

SanjivMeher
Kilo Patron
Kilo Patron

Does it work on an onLoad client script?


Please mark this response as correct or helpful if it assisted you with your question.

It does work in an onLoad client script.

ccajohnson
Kilo Sage

Are the fields visible on the form. By default, the Short description field is not visible. Also, make sure that you are selecting the correct field to trigger onChange. If you can provide a screen shot of what you have so far it would be helpful.

I thought short description was a default field in Problem. Either way, the fields are visible on the form I'm testing on. The client script:

find_real_file.png

A random problem I'm testing on:

find_real_file.png