The CreatorCon Call for Content is officially open! Get started here.

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

changeFieldLabel sets the colour of the field background as an extra way to highlight the status.

Brad Bowman
Kilo Patron
Kilo Patron

This makes more sense than having 2 UI policies. I noticed you are using contract_state in your condition, but state in your scripts.  Have you tried alerting on the same field as the condition to be sure they're in sync?

Cheers Brad - I think there was a reason why we did two initially but can't remember now.Possibly just lack of relevant knowledge at the time.

I had a look at the field names as I know that some forms have two or more "state fields". Our contract form has one with the label "Contract State" and the column name of "state".

Also, the bit of the script that retrieves the contract state states it correctly.