UI Policy Execute If False Not Working

Andrew Bettcher
Kilo Sage

Hi,

 

Got a single UI policy with one condition - contract.contract_state = active. I;ve got this script in the "Execute if true" field:

function onCondition() {

// This first part of the code adds a message banner stating the contract is active and changes the word contract which is alongside the contract field to green
	g_form.removeDecoration('u_contract', 'icon-alert', 'Contract has expired', 'color-red');
	g_form.clearMessages();
	changeFieldLabel('u_contract', 'Contract', 'green');
	g_form.addDecoration('u_contract', 'icon-check-circle', 'Contract is active', 'color-green');
	
	var comp = g_form.getReference('u_contract', setVis);
}

function setVis (comp){
                        {
   
// The following adds the support maintainer details (MTI or Vendor) & description field based on the contract information							
        g_form.addInfoMessage('<font color="green"><b>Contract is </b>' + comp.state + '<font color = "black"><b><br><br>This contract is <font color="red">' + comp.u_maintenance + '<font color="black"> maintained.' + '<br><b> The Description for this contract states:   <font color="red"></b>' + comp.description);
							
						}
}
  

And this script in the "Execute if False" field:

function onCondition() {

// This first part of the code adds a message banner stating the contract is active and changes the word contract which is alongside the contract field to green
	g_form.removeDecoration('u_contract', 'icon-alert', 'Contract has expired', 'color-red');
	g_form.clearMessages();
	changeFieldLabel('u_contract', 'Contract', 'red');
	g_form.addDecoration('u_contract', 'icon-check-circle', 'Contract is active', 'color-red');
	
	var comp = g_form.getReference('u_contract', setVis);
}

function setVis (comp){
                        {
   
// The following adds the support maintainer details (MTI or Vendor) & description field based on the contract information							
        g_form.addErrorMessage('<font color="green"><b>Contract is </b>' + comp.state + '<font color = "black"><b><br><br>This contract is <font color="red">' + comp.u_maintenance + '<font color="black"> maintained.' + '<br><b> The Description for this contract states:   <font color="red"></b>' + comp.description);
							
						}
}

 

(i.e. the same barring a few style differences and word changes).

The problem is that no matter how the condition resolves, the script always shows the "Execute if False" script. Even when I can see that the contract_state field shows as active.

I;ve tried it with the "reverse if false" ticked and unticked (although I think this only applies if there are policy actions) but the problem is that, to ServiceNow, "Expired" and "Active" aren't opposites, they're just two different choices in a lists. Either way though, as far as I can see, if the condition is true (contract state = active) then the first script should run and, if the condition is false (contract state = anything else) then the second script should run.

Why doesn't it?

7 REPLIES 7

harishdasari
Tera Guru

Hello Andrew,

Code/script is Identical in  Execute if true and Execute if false, so no matter condition is matched or not the script will be executed.

this is something like On-Load client script. when ever the form loads this script will be execute regardless of the conditions.

Thanks.

 

 

 

Hi - They aren't identical. One is info message and the other is error message.

I think you are right. Needs to be a client script. I've test it and report back.

Thank you.

Ashutosh Munot1
Kilo Patron
Kilo Patron

Hi,

what is this changeFieldLabel

 

Thanks,
Ashutosh