- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2024 03:09 AM
Hello all,
I am developing some complex forms where many fields disappear and appear, become mandatory and not-mandatory based on the choice of the user on some variables. However, I always notice some seriously inconsistent behavior. For example, fields disappear when we move from one form layout to the other.
I could not figure out the logic behind these. The "order" column does not seem to make much of a difference.
Does anyone know the best practices to tackle the complex, dynamic, changing-with-the-selection-of-the-users forms with multiple UI Policies defined on the same variables?
Thank you!
Best,
Firat
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2024 03:24 AM
Sure, here are some best practices to tackle complex, dynamic forms with multiple UI Policies defined on the same variables:
1. **UI Policies Order**: The order of UI Policies does matter. The lower the order, the higher the priority. If you have multiple UI Policies acting on the same field, ensure they are ordered correctly.
2. **UI Policy Conditions**: Make sure your UI Policy conditions are not conflicting with each other. If two UI Policies have opposite actions on the same field, it can cause inconsistent behavior.
3. **Use of Scripts**: If your form is very complex, consider using client scripts instead of UI Policies. Client scripts provide more flexibility and control over form behavior.
4. **Group Related Fields**: Group related fields into sections or tabs. This can help manage the visibility and mandatory state of fields more effectively.
5. **Use of Catalog Client Scripts**: For service catalog items, use catalog client scripts to control the behavior of variables based on user selection.
6. **Use of GlideForm (g_form) API**: The GlideForm (g_form) API provides methods to control form fields. You can use these methods in your client scripts to control the behavior of your form fields.
7. **Testing**: Always test your form behavior thoroughly. Make sure all UI Policies and client scripts are working as expected.
8. **Documentation**: Document your form behavior and the logic behind it. This can help you and others understand the form behavior better.
Here is a sample code for a client script that makes a field mandatory based on user selection:
javascript
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
if (newValue == 'some_value') {
g_form.setMandatory('field_name', true);
} else {
g_form.setMandatory('field_name', false);
}
}
In this script, replace 'some_value' with the value that should make the field mandatory, and 'field_name' with the name of your field.
nowKB.com
For asking ServiceNow-related questions try this :
For a better and more optimistic result, please visit this website. It uses a Chat Generative Pre-Trained Transformer ( GPT ) technology for solving ServiceNow-related issues.
Link - https://nowgpt.ai/
For the ServiceNow Certified System Administrator exams try this :
https://www.udemy.com/course/servicenow-csa-admin-certification-exam-2023/?couponCode=NOW-DEVELOPER
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2024 03:15 AM - edited 02-23-2024 03:19 AM
I shared my experience. In cases where there was no clash of UI policies, I used the 'reverse If 'false -> true' technique. However, when there was a need to create multiple UI policies, I set this field to false so that opposite actions would not be executed. If you don't need this technique, try setting the 'reverse if false' to false.
If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2024 03:18 AM
I am not sure if you will find anything such as best practice for UI policies to hide and show logic.
Few things that comes to mind is to first build a strategy, in which manner you want to show/hide your fields, then start building the UI policy.
One thing that becomes very important during this - Reverse, if false and On load checkboxes.
Be very clear when to mark these as true and have good understanding of this functionality.
And orders are valid and works just fine, you need to be sure how the execution occurs, and if the client script doesn't collide with your UI policy.
If you can share more details, probably it can give us more insight to assist you
Aman Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2024 03:20 AM
Hi @mfhaciahmetoglu ,
You can verify the field 'Reverse if false' based on your requirement and also you can check if there are multiple UI Policy actions on the same field/variable because that could cause a conflict.
Please mark this response as correct or helpful if it assisted you with your question.
Best Regards,
Rutuja Khalate
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2024 03:22 AM
Tech Guru's already replied . This video might be helpful
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************