Show variable help text based on the condition

ramwons
Kilo Expert

Hello,

I want to show help text based value selected in a previous variable.

Variable1 -> Yes/No

Variable2.

If Variable1 is set as YES then the help text of Varible2 should be "Test 1".

If Variable1 is set as NO then the help text Variable2 should be "Test 2".

I have created a UI policy and in script I use g_form.showFieldMsg.

But whenever I change the value in Variable1 the both the help text are displaying one down the another. Help text is not getting cleared based on the value selected.

Best Regards,

Ram

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you cannot set dynamic help text directly

if you are using showFieldMsg then just when your onchange client script starts you need to hide the field message using hideFieldMsg

you should use client script when scripting is involved

please share your script

Regards
Ankur

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

View solution in original post

5 REPLIES 5

Sagar Pagar
Tera Patron

Hello,

 

Try below script in onChange catalog client script, It will gives you result as expected. change your variable names and messages as per need.

function onChange(control, oldValue, newValue, isLoading) {
	if (isLoading || newValue == '') {
		g_form.hideFieldMsg('variable2','true');
		return;
	}

	if(newValue == 'yes'){
		g_form.hideFieldMsg('variable2','true');
		g_form.showFieldMsg('variable2','Test 1','info');

	}
	if(newValue == 'no'){
		g_form.hideFieldMsg('variable2','true');
		g_form.showFieldMsg('variable2','Test 2','info');

	}

}

 

Thanks,

Sagar Pagar

The world works with ServiceNow