I want to set the boolean field as true
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2020 12:25 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2020 12:35 AM
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:
- function onChange(control, oldValue, newValue, isLoading, isTemplate) {
- if (isLoading || newValue == '') {
- if(g_form.getValue('category')=='help')
- g_form.setValue(<'resource field's back end name'>,true);
- return;
- }
- if(g_form.getValue('sub_category')=='vpn')
- g_form.setValue(<'resource field's back end name'>,true);
- }
Thanks,
Mohit Kaushik
Mohit Kaushik
ServiceNow MVP (2023-2025)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2020 12:56 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2020 02:11 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2020 02:51 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader