Display the choice value based on true/false field

tanz
Tera Expert

I have a true/false field A for the cmdb_ci table. When the field is true for the CI in cmdb_ci table and then I will raise an incident with the cmdb_ci , the particular choice A(I have also created a category choice as A same as field name) should be shown in the category of the Incident else it will not be shown. 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you should write onChange client script on cmdb_ci field on INC form

1) clear all the options from category

2) then based on true false value add the option you want

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

	g_form.clearOptions('category');

	var ref = g_form.getReference('cmdb_ci', callBackMethod);

}

function callBackMethod(ref){

	if (ref.u_field.toString() == "true") {
		g_form.addOption('category', 'choiceValue', 'choiceLabel');
	}
}

regards
Ankur

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

View solution in original post

10 REPLIES 10

FYI, UI Policies working On Load as well as On Change.

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you should write onChange client script on cmdb_ci field on INC form

1) clear all the options from category

2) then based on true false value add the option you want

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

	g_form.clearOptions('category');

	var ref = g_form.getReference('cmdb_ci', callBackMethod);

}

function callBackMethod(ref){

	if (ref.u_field.toString() == "true") {
		g_form.addOption('category', 'choiceValue', 'choiceLabel');
	}
}

regards
Ankur

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

Hi Ankur,

I am getting an error for the code

find_real_file.png

find_real_file.png

Hi,

your onChange should be on Configuration Item field and not business service

the field u_enable_hypercase_category_setup is on business service table or cmdb_ci table?

you mentioned it's on cmdb_ci table; so update line 6 as this

	var ref = g_form.getReference('cmdb_ci', callBackMethod);

Regards
Ankur

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

@tanz 

Thank you for marking my response as helpful.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards
Ankur

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