We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

Cleanest way to simplify UI Action conditions

Michael McNulty
Tera Expert

Hello, 

 

I'm trying to build a condition for a UI Action that essentially says "if the RITM state is not closed skipped, closed complete, or closed incomplete" show this UI Action. 

Below is the only way I can think of doing it (that actually works):
current.state != 3 && current.state != 4 && current.state != 7

 

What I want to do (which doesn't work) is:
(current.state != 3, 4, 7)

What I've tried (Which didn't work):
(current.state != 3 || 4 || 7)

(current.state != 3, 4, 7)


Obviously there's no huge benefit to this beyond cleaning up the code a bit, but I'm just curious if anyone out there has found a way to do this cleaner than adding a bunch of && conditions like this.

 

Thanks in advance to anyone that contributes!

1 ACCEPTED SOLUTION

Tai Vu
Kilo Patron

Hi @Michael McNulty ,

From the conditions, I can see that we only display the button when RITM is Active. So you can simplify the condition as.

 

current.active;

 

 

Also, we can define a function in a script include and call in the Condition box.

Sample:

 

new CatalogUtils().isVisible(current.getValue('state'));
isVisible: function(state){
	return state !== '3' && state !== '4' && state !== '7';
},

 

 

You can also try some other ways around like

 

"3,4,7".indexOf(current.state) == -1;

 

 

Let me know if it works for you.

 

Cheers,

Tai Vu

View solution in original post

2 REPLIES 2

SVimes
Kilo Sage

I did a little searching on this. What I'm finding is this is not going to be possible. If conditions are longer/more complex, using a Script Include to validate is a better option.

Sable Vimes - CSA

Tai Vu
Kilo Patron

Hi @Michael McNulty ,

From the conditions, I can see that we only display the button when RITM is Active. So you can simplify the condition as.

 

current.active;

 

 

Also, we can define a function in a script include and call in the Condition box.

Sample:

 

new CatalogUtils().isVisible(current.getValue('state'));
isVisible: function(state){
	return state !== '3' && state !== '4' && state !== '7';
},

 

 

You can also try some other ways around like

 

"3,4,7".indexOf(current.state) == -1;

 

 

Let me know if it works for you.

 

Cheers,

Tai Vu