URGENT HELP- How to make sub-category mandatory only if it has dropdown.

ST9
Tera Contributor

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.find_real_file.png

 

1 ACCEPTED SOLUTION

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

View solution in original post

17 REPLIES 17

Gaurav Rotke1
Kilo Guru

Hi ST,

You can use UI policy for this in following manner:

Please mark correct and helpful.

Thank you 

Gaurav Rotke

OlaN
Giga Sage
Giga Sage

Hi,

Please avoid creating duplicate questions.
Keep the discussion going in the original question.
https://community.servicenow.com/community?id=community_question&sys_id=7ece3f7bdb3c11501227db85ca96...

Also, no matter how urgent your requirement is, take a few minutes extra to specify your question.
Have a look at the 10+ tips article.
That way you are more likely to get a complete and correct answer the first time around, which saves time for everyone.

Martin Ivanov
Giga Sage
Giga Sage

Hi. If my answer has helped you resolve your issue, Please mark Correct and Helpful. This way, other users may also benefit from the thread. Thanks!
Martin Ivanov
Community Rising Star 2022


Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Martin Ivanov
ServiceNow MVP 2023, 2024