Need help with choice field not selecting other choices. It automatically selects back to the first option regardless of what choice I select.

John Clyde Ap_a
Giga Expert

Hello, I have this field in my form that has been dynamically added through a client script

find_real_file.png

My current problem is that it won't let me choose other choices, for example when I choose Medium or Large, it just reverts back to small automatically. This goes for other records in the table too. 

Here is my script

function onChange(control, oldValue, newValue, isLoading) {

	if (isLoading) {
		return;
	}
	
	if(newValue == ''){
		g_form.clearOptions('u_choice_2');
	}

	var choice = g_form.getValue('u_choice_2');
	var ref = g_form.getReference('u_reference_1', callBackMethod);	// reference field name here
	
function callBackMethod(ref, choice){
	//g_form.setValue('u_choice_5', 'Small - '+ref.small+' '+'Medium - '+ref.medium+' '+'Large - '+ref.large);
		// give field name here
	g_form.clearOptions('u_choice_2');
	g_form.addOption('u_choice_2',ref.small ,'Small - '+ ref.small);
	g_form.addOption('u_choice_2',ref.medium ,'Medium - '+ ref.medium);
	g_form.addOption('u_choice_2',ref.large ,'Large - '+ ref.large);

}	

}
 

 

Please help, I cannot figure out what is causing it.

1 ACCEPTED SOLUTION

Kieran Anson
Kilo Patron

Enable debugging and watch the field to see what client script / policy is causing the field change

Debugging Client Scripts | ServiceNow Developers

View solution in original post

3 REPLIES 3

Kieran Anson
Kilo Patron

Enable debugging and watch the field to see what client script / policy is causing the field change

Debugging Client Scripts | ServiceNow Developers

Allen Andreas
Administrator
Administrator

Hi,

I'd recommend following Kieran's advice to learn how to troubleshoot.

However, just looking at your code, your callback function is clearing the choice field, then resupplying it with the 3 values...which, without a "none" is going to default to the first choice, which you have as small.

So you'd need to review your code and think through what you're trying to do. Why onChange would you be clearing all options, then adding all 3 back everytime that field changes value.

You're doing nothing with the "choice" parameter in your callback function.

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Hi,

I'm glad you found a correct answer that works for you.

If you can, please let us know what resolved your issue as learning to troubleshoot it is great and of course the best way to learn and all that, but was it what I was mentioning above and pointed out?

Just wanted to check-in and see if my reply guided you appropriately?

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!