Can I set a query inside an UI Action Condition?

GuiReis
Tera Contributor

I have this UI Action that I only want visible if a value stored on a record from a different table is true.

The condition would look something like this:

new GlideRecord('other_table').addEncodedQuery(active=true^foo=current.foo).query().next().bar == true && current.status == '1'

However, when I save, SN gives me this error:
Use two equal signs to test equality; conditions should not do assignment

What am I doing wrong?

1 ACCEPTED SOLUTION

AnirudhKumar
Mega Sage
Mega Sage

Move the gliderecord part of the condition to a script include and call the script include from the condition field.

Thats the traditional way to do it.

 

Edit : You will have to return a true or a false from the script include based on your requirement

View solution in original post

3 REPLIES 3

AnirudhKumar
Mega Sage
Mega Sage

Move the gliderecord part of the condition to a script include and call the script include from the condition field.

Thats the traditional way to do it.

 

Edit : You will have to return a true or a false from the script include based on your requirement

Teju Dhoran
Kilo Sage
Kilo Sage

Hi,

Please check below link:

How to call script include from the "condition" section of a UI Action? - Developer Community - Ques...

Calling a Script Include in a UI Action? - Developer Community - Question - ServiceNow Community

you can write this login in script include to return true/false and call script include in condition.

 

Thanks,

Teju D.

DrewW
Mega Sage
Mega Sage

I know this was answered but you can do it the way you were, but you need to do it a bit differently

new GlideQuery("other_table").where("active", true).where("foo", current.foo).where("bar", true).select().toArray(1).length > 0  && current.status == '1'
 
So if the query returns at least 1 row then you have a record in the db that is active=true^foo=current.foo^bar=true.
 
 
https://developer.servicenow.com/dev.do#!/reference/api/quebec/server/no-namespace/GlideQueryAPI?navFilter=GlideQuery