- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2023 01:11 AM
Hi,
I have the fields Category and Sub Category on the incident table. Sub Category values are dependent on Category. For some values on category there are sub categories and some of the values of categories don't have values in sub category. How can I make Sub Category field mandatory only if he has values according to the Category that was chosen ?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2023 09:18 AM
This solution is tried and tested in the PDI and it is giving correct response.
Please check my attached screenshot from my PDI
If my answer solved your issue, please mark my answer as ✅ Correct & 👍Helpful based on the Impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2023 05:46 AM
@Sai Shravan @Prince Arora this is the code Im using. The first time that Im choosing a category, Im getting Alert count of 1, even though Im choosing a category that has 18 choices. Then the 2nd time that Im chossing a category im getting alert count of 1 + the choices that I was supposed to get in the first time so total 19.
for some reason its adding the choices and it start from one in the first time that Im choosing a category.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2023 06:05 AM - edited 03-12-2023 06:48 AM
Hi @Alon Grod,
The None option is also counted in the options and you can try by changing the if condition to
if (options > 1)
Shravan
Please mark this as helpful and correct answer, if this helps you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2023 06:40 AM
Please change your client script as onChange of "subcategory" and mention the code snippet as mention in below code as it is taking 'none' as a option so you will get the value as n+1 always.
As per the previous code there is a lag between the code because once you selected the option it will change the options and return the output of the subcategories of previous selected "category"
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
var subcat = g_form.getControl('subcategory');
var options = subcat.options.length;
alert(options);
return;
}
//Type appropriate comment here, and begin script below
else {
var subcat = g_form.getControl('subcategory');
var options = subcat.options.length;
alert(options);
if (options > 0) {
g_form.setMandatory('subcategory', true);
}
}
If my answer solved your issue, please mark my answer as ✅Correct & 👍Helpful based on the Impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2023 07:39 AM
@Prince Arora it is still showing me the previous choices and not the actual choices of the chosen category and sub category
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2023 08:08 AM
Hi @Alon Grod ,
I hope the alert is showing the previous sub - category count, but the value are as per the selected category and the sub-category becoming mandatory.
you can try by changing the if condition to
if (options > 1)
Shravan
Please mark this as helpful and correct answer, if this helps you