Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

UI policy - Condition issue

Mike49
Tera Contributor

I have a simple UI Policy that shows a field message when the user selects Option A or Option B, a field message appears. 

If the user selects Option A, the field message shows as expected. 

However, if the user selects Option B after Option A was select first, the field message disappears.  I have no code that clears all field messages.

 

It's behaving as if the condition is evaluating to false but it should be evaluating to true .

 

 

1 ACCEPTED SOLUTION

Sarthak Kashyap
Mega Sage

Hi @Mike49 ,

 

Please check reverse if false is checked and you can add below script 

function onCondition() {
	alert("Running");

    var val = g_form.getValue('category');

    g_form.hideFieldMsg('category'); // clear old message

    if (val == 'inquiry' || val == 'software') {
		alert("Running Val = " + val);
        g_form.showFieldMsg('category', 'Your message goes here', 'info');
    }


}

 

 

 

If this will not work you can also use client script for your problem which runs on change of your field and add below code 

function onChange(control, oldValue, newValue) {
    g_form.hideFieldMsg('your_choice_field');

    if (newValue == 'Option A' || newValue == 'Option B') { // backend value of option A& B
        g_form.showFieldMsg('your_choice_field', 'Your message goes here.','info');
    }
}

 

Please mark my answer correct and helpful if this works for you
Thanks and Regards,

Sarthak

 

 

View solution in original post

3 REPLIES 3

Nawal Singh
Tera Guru

Hi @Mike49 ,

If Reverse if false is enabled, then when the UI Policy condition evaluates to false

Please review in your case !

 

If you found my response helpful, please mark it as helpful and accept it as the solution.

Thank you
Nawal Singh

Hemanth M1
Giga Sage
Giga Sage

Hi @Mike49 ,

I have observed this, it wouldn't execute the 'if' condition script if a condition is met already, unless it executes the 'else' condition once


Option A and Option B will not work.
Option A, Option C, and again Option A or B works


Why don't you try an onChange client script instead?

 

 

Accept and hit Helpful if it helps.

Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025

Sarthak Kashyap
Mega Sage

Hi @Mike49 ,

 

Please check reverse if false is checked and you can add below script 

function onCondition() {
	alert("Running");

    var val = g_form.getValue('category');

    g_form.hideFieldMsg('category'); // clear old message

    if (val == 'inquiry' || val == 'software') {
		alert("Running Val = " + val);
        g_form.showFieldMsg('category', 'Your message goes here', 'info');
    }


}

 

 

 

If this will not work you can also use client script for your problem which runs on change of your field and add below code 

function onChange(control, oldValue, newValue) {
    g_form.hideFieldMsg('your_choice_field');

    if (newValue == 'Option A' || newValue == 'Option B') { // backend value of option A& B
        g_form.showFieldMsg('your_choice_field', 'Your message goes here.','info');
    }
}

 

Please mark my answer correct and helpful if this works for you
Thanks and Regards,

Sarthak