work notes manadate
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-29-2024 03:27 AM - edited 10-29-2024 03:30 AM
Hi Team,
we have countries field (filed type is "list") on incident by default we are populating one country name in that field now the requirement is if any one trying to add any other country into that field we have to make work notes mandatory so that user can add comments why he is adding the country can any one help me in the script or how to achieve this

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-29-2024 03:33 AM
An onChange client script could be used to set the work notes field as mandatory after a field value changes. If you're not familiar with client scripts, there is a learning guide on the developer website: https://developer.servicenow.com/dev.do#!/learn/courses/xanadu/app_store_learnv2_scripting_xanadu_sc...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-29-2024 03:37 AM
You can achieve this using an UI policy:
- Create an UI policy. Set up the condition like the “countries != <The country you defaulted>”. Check onload to false. Reverse if false to true. Setup UI policy action to make worknotes mandatory.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-29-2024 04:27 AM
Hi @Shabbir1 ,
You can create an OnChange Client script as described below:
In the script provided, you can modify the If condition. If you want to compare the country added after the form loads, use (new_length > old_length). However, if you want to check whether the country field contains more than one country, you can change the if loop condition to (new_length > 1).
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var new_length = newValue.split(',').length;
var old_length = oldValue.split(',').length;
if (new_length > old_length) {
g_form.setMandatory('work_notes', true);
}
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If you found my response **helpful**, I’d appreciate it if you could take a moment to select **"Accept as Solution"** and **"Helpful"** Your support not only benefits me but also enriches the community.
Thank you!
Moin Kazi
www.linkedin.com/in/moinuddinkazi
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~