- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-01-2017 05:11 PM
Hi everyone,
I am trying to create a field on a category table and want to reference the default value of that field on a HR case table
For example:
Sub Category Value is REP1 for Category called Data/Report Request
I would like REP1 to populate on the HR case form when the Category Data/Report Request is selected.
Any Ideas on how i can achieve this?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-01-2017 07:49 PM
Hi Karan,
Below script should actually work and shouldn't change the value back to the previous one. Can you put some alert as below?
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}
else if(newValue != oldValue){
alert('newValue is '+newValue);
var category = g_form.getReference('u_category', populateSubCategory);
}
function populateSubCategory(category) {
g_form.setValue("u_sub_category",category.u_sub_category);
}
}
Please mark this response as correct or helpful if it assisted you with your question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-01-2017 05:28 PM
Hi Karan,
You can make the subcategory field a dependednt field of category, but that will just filter the subcategory related to that category but wont set the category.
To set the category on Selection, you will need an onChange client script to do that.
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-01-2017 05:44 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-01-2017 05:48 PM
If you are prototyping this solution, perhaps use the following
var grHRCategory= g_form.getReference('u_category', populateSubCategory);
function populateSubCategory(grHRCategory) {
g_form.setValue('u_sub_category', grHRCategory.u_sub_category);
}
Once you have proved your concept, refactor to use GlideAjax.
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-01-2017 07:24 PM
Thanks Paul. This is very helpful! i was able to set the default value for sub category by using this script.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}
else if(newValue != oldValue){
var category = g_form.getReference('u_category', populateSubCategory);
}
function populateSubCategory(category) {
g_form.setValue("u_sub_category",category.u_sub_category);
}
}
However, i have one challenge. The user needs the ability to change the sub category value and in this scenario it should not get the value from the category table on load. Right now, if i change the sub category value and hit save the value defaults back to the one mentioned in the category table, any ideas to get around that?