Category on Incident only available when another field's value is true.

Community Alums
Not applicable

I have a category and a list of subcategories on our incident table. The category should only be visible if there is a value of true on an external user field. What is the best approach to accomplish this?

2 ACCEPTED SOLUTIONS

Amit Gujarathi
Giga Sage
Giga Sage

HI @Community Alums ,
I trust you are doing great.
Here's a script that will achieve this functionality:

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading) {
        return;
    }

    // Assuming the field name of the custom true/false field is 'external_user_field'
    // and the internal name of the category field is 'category'
    var externalUserValue = g_form.getValue('external_user_field');

    if (externalUserValue === 'true') {
        g_form.setDisplay('category', true); // Show the category field
    } else {
        g_form.setDisplay('category', false); // Hide the category field
    }
}

Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi



View solution in original post

Hi @Community Alums 

 

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.

 

Best regards

Anders

If my answer has helped with your question, please mark my answer as the accepted solution and give a thumbs up.

Best regards
Anders

Rising star 2024
MVP 2025
linkedIn: https://www.linkedin.com/in/andersskovbjerg/

View solution in original post

9 REPLIES 9

Community Alums
Not applicable

Hi Kai,

 

It sounds like your solution is close to what I am trying to do. OOB there are some category options in the category/subcategory fields. These should show on the incident form when the user is not external. We have added a checkbox field 'external_user' that if checked we want the category field to only give one option. 

thought so.

 

You can use g_form.removeOption to strip all the categories you want to remove one by one.

or a more efficient way would be to remove all options, and just add back the one you want to keep.

 

something like this as an onChange script

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }

   var user = g_form.getReference('caller_id',extUser);

   function extUser(user){
	if (user.u_external_user == 'true'){ //change field name as required
		
		g_form.clearOptions('category');
		g_form.addOption('category','external_user','External User'); //change category to match the one you want to retain. Syntax is 'field', 'value', 'display name'		
	}   }   
}

 you would then replicate that as an onLoad script for when the record loads.

 

rules apply as mentioned above, if you change the user to a 'non external user' - the category list will be gone until you hit save and the page re-loads.

 

if that helps or has answered your question, please click the corresponding button 🙂

Amit Gujarathi
Giga Sage
Giga Sage

HI @Community Alums ,
I trust you are doing great.
Here's a script that will achieve this functionality:

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading) {
        return;
    }

    // Assuming the field name of the custom true/false field is 'external_user_field'
    // and the internal name of the category field is 'category'
    var externalUserValue = g_form.getValue('external_user_field');

    if (externalUserValue === 'true') {
        g_form.setDisplay('category', true); // Show the category field
    } else {
        g_form.setDisplay('category', false); // Hide the category field
    }
}

Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi



AndersBGS
Tera Patron
Tera Patron

Hi @Community Alums ,

 

Create a scripted UI Policy to check if the user is external or not (you need some verification on the form). Based on this, your UI policy action should be category field visible set to true.

 

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.

 

best regards

Anders 

If my answer has helped with your question, please mark my answer as the accepted solution and give a thumbs up.

Best regards
Anders

Rising star 2024
MVP 2025
linkedIn: https://www.linkedin.com/in/andersskovbjerg/

Hi @Community Alums 

 

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.

 

Best regards

Anders

If my answer has helped with your question, please mark my answer as the accepted solution and give a thumbs up.

Best regards
Anders

Rising star 2024
MVP 2025
linkedIn: https://www.linkedin.com/in/andersskovbjerg/