- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-27-2022 02:46 AM
Hi All,
How can i make a sub-category 2 field mandatory (which is dependent on sub-category 1 field) only when it has dropdown when the case is getting resolved.
I tried with UI policy but the problem is few of the sub-cat2 does not have any dropdown. So while using UI policy it will make sub-cat2 mandatory all the time even though it does not have any dropdown.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-28-2022 04:50 AM
1) You are using many brackets unnecessarily
2) You should pass sysid for assignment group reference fields
Update your script as below and pass sysids where ever I mentioned in script
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
if((newValue == '101') && ((g_form.getValue('assignment_group')=="sysid of group1")||(g_form.getValue('assignment_group')=="sysid of group2")||(g_form.getValue('assignment_group')=="sysid of group3")||(g_form.getValue('assignment_group'))=="sysid of group4"))
{
var subcat2 = g_form.getControl('u_sub_category_2');
var options = subcat2.options.length;
if(options > 1)
{
g_form.setMandatory('u_sub_category_2', true);
}
}
}
Mark as correct and helpful if it solved your query.
Regards,
Sumanth

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-27-2022 03:29 AM
Did you try my script shared below?
It will make the subcategory mandatory if it has any options in it.
You need to change the state to resolved then only the client script will trigger.
If you just change the category value, the client script will not trigger.
Regards,
Sumanth

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-27-2022 03:16 AM
Hi,
Deactivate your ui policy and do the below.
Write an OnChange client script on state field as below
if(newValue == 'resolved') //check backend value for resolved
{
var subcat2 = g_form.getControl('u_sub_category_2'); //check backend value for subcategory 2 field
var options = subcat2.options.length;
if(options > 1)
{
g_form.setMandatory('u_sub_category_2', true);
}
}
Mark as correct and helpful if it solved your query.
Regards,
Sumanth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-27-2022 03:43 AM
Hi Sumanth,
I tried your code an it worked. Can you tell me how can i add one more condition to check for only specific groups. It should be mandatory only for few assignment group and when state changes to Resolve.
i tried ading group condition then it was not working as expected, can you tell me what i am doing wrong
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
if((newValue == '101') && (((g_form.getValue('assignment_group'))=="General HR Inquiries")||((g_form.getValue('assignment_group'))=="General HR Inquiries_Test")||((g_form.getValue('assignment_group'))=="General HR Inquiries_Dev")||((g_form.getValue('assignment_group'))=="General HR Inquiries_Prod")))
{
var subcat2 = g_form.getControl('u_sub_category_2');
var options = subcat2.options.length;
if(options > 1)
{
g_form.setMandatory('u_sub_category_2', true);
}
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-28-2022 04:50 AM
1) You are using many brackets unnecessarily
2) You should pass sysid for assignment group reference fields
Update your script as below and pass sysids where ever I mentioned in script
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
if((newValue == '101') && ((g_form.getValue('assignment_group')=="sysid of group1")||(g_form.getValue('assignment_group')=="sysid of group2")||(g_form.getValue('assignment_group')=="sysid of group3")||(g_form.getValue('assignment_group'))=="sysid of group4"))
{
var subcat2 = g_form.getControl('u_sub_category_2');
var options = subcat2.options.length;
if(options > 1)
{
g_form.setMandatory('u_sub_category_2', true);
}
}
}
Mark as correct and helpful if it solved your query.
Regards,
Sumanth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-29-2022 03:24 AM
@ST
Feel free to reach out if you have further questions or else you can mark an answer as correct and helpful to close the thread so that it benefits future visitors also.
Regards,
Sumanth