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

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

SumanthDosapati
Mega Sage
Mega Sage

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

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);
}
}
}

 

find_real_file.png

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

@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