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.

How to filter list by adding javascript in the conditions for a string type field

nitheshkumar74
Tera Contributor

Hello,

I have created a system property which stores the string values (for example: hardware, software etc.).
In the incident list I am trying to filter with short description field, by adding a condition as
short description is one of and using the javascript to call system property I created and get the values from it as below. However, I am seeing undefined as return value from the javascript code. 

I have tried with script include but for some reason it isn't working or showing the same issue as below. The idea is to get this logic and use in the business rule when to run condition for a string field to check if the values are one of from the system property. Kindly help to resolve this issue.

nitheshkumar74_0-1700039300430.png

 

nitheshkumar74_1-1700039379631.png

 

3 REPLIES 3

Maik Skoddow
Tera Patron
Tera Patron

Hi @nitheshkumar74 

basically you are on the right path and using prefix "javascript:" along with any simple method invocation will but, as described at https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0746219

However, using "gs.getProperty()" doesn't seem to work for me either. Really strange. Instead you should you use a custom Script Include. Refer to the linked KB article for examples.

Maik

Ankur Bawiskar
Tera Patron
Tera Patron

@nitheshkumar74 

I haven't tried the way you mentioned.

But you can try to use this approach if your didn't work

1) create client callable classless script include something like this and return that property value

2) then call that script include in filter condition

short description [IS ONE OF] javascript: getPropertyValue()

AnkurBawiskar_0-1700046741484.png

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Antoni Zahariev
Tera Guru

The instructions for creating a scripted filter are in this article: Create scripted filters

So, the query "active=true^short_description=<your_string>" should be placed in the function and then return the relevant [sys_id]s