work notes manadate

Shabbir1
Tera Contributor

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

 

Shabbir1_1-1730197654374.png

 

 

3 REPLIES 3

Kieran Anson
Kilo Patron

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... 

Ravi Peddineni
Kilo Sage

@Shabbir1 

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. 

Moin Kazi
Kilo Sage
Kilo Sage

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

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~