The CreatorCon Call for Content is officially open! Get started here.

I want to set the boolean field as true

chinna
Mega Guru

Hi team,

in the incident form i have a field "resource(true/false)" field.

here my exact requirement is when the category field value changes to "help" i want to set the eligible field as true.

and when the sub category changes to "vpn" i want to set the eligible field as true. 

how can i acheive this, can some one help me with on change client script for this .

 

Thanks,

Chinna

5 REPLIES 5

Mohit Kaushik
Mega Sage
Mega Sage

Hi You can write an onchange client script and you can mention the code something like this:

run the script on change of subcategory.

//demo example of onChange client script:

  1. function onChange(control, oldValue, newValue, isLoading, isTemplate) {
  2.     if (isLoading || newValue == '') {
  3.        if(g_form.getValue('category')=='help')
  4.         g_form.setValue(<'resource field's back end name'>,true);
  5.           return;
  6.     }
  7.     if(g_form.getValue('sub_category')=='vpn')
  8.     g_form.setValue(<'resource field's back end name'>,true);
  9.    
  10. }

 

Thanks,

Mohit Kaushik

Thanks,
Mohit Kaushik
ServiceNow MVP (2023-2025)

Alok Das
Tera Guru

Hi Chinna,

You need to create 2 onChange Client Script, one on change of category and second on change of sub category. Please find the below code for Category onChange client script:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
	if (isLoading || newValue === '') {
		return;
	}
	if(newValue=='help')//replace help with the actual backend value of help
		g_form.setValue('resource',true);//replace resource with the actual backend field name of resource
	else
		g_form.setValue('resource',false);//replace resource with the actual backend field name of resource
}

 

Code for Subcategory onChange client script:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
	if (isLoading || newValue === '') {
		return;
	}
	if(newValue=='vpn')//replace help with the actual backend value of vpn choice
		g_form.setValue('resource',true);//replace resource with the actual backend field name of resource
	else
		g_form.setValue('resource',false);//replace resource with the actual backend field name of resource
}

Note: above script will change the field value to false if category and subcategory is not help or vpn. If your subcategory vpn is dependent on category help then you need to slightly modify the code to work.

Kindly mark my answer as Correct and Helpful based on the Impact.

Regards,

Alok

Prasant Kumar 1
Kilo Sage

Hi,

You have to write 2 Client Scripts:-

 

1. Client Script:-(onChange on Category):-

if(g_form.getValue('category') =='help'){

g_form.setValue('resource_field',true);

}

 

2.Client Script:- (onChange on Sub-category):-

if(g_form.getValue('sub_category') == 'vpn'){

g_form.setValue('resource_field',true);

}

 

If i was able to solve your query, please mark my answer correct and helpful.

Thanks & regards

Prasant kumar sahu

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you can use business rule for this; before insert/update business rule

I assume for combination of category+sub category you want to make the field as true and not when either of value matches

if(current.category == 'help' && current.sub_category == 'vpn')

current.resource = true;

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

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