Use PDIs? Take our 5-minute survey to help shape the PDI roadmap.

How to add a Script to a Search Sources condition.

Yudai Yamamoto
Mega Guru

I want to add a condition using a script to Search Sources of AI Search.
If you know how to add it, please let me know.

1 ACCEPTED SOLUTION

Isaac Vicentini
Mega Sage

Hi @Yudai Yamamoto!

 

Currently it is not possible using scripts to perform filters in Search Source , see:

 

âž” ServiceNow Docs - Search sources

IsaacVicentini_0-1727889711871.png

 

Alternatively, you can work with ACLs, if the user does not have permission to see a record due to security permissions, it will automatically not appear in the AI ​​Search results.


If my answer helped you in any way, please mark it as Helpful / Accept as Solution 🎯

Regards,

Isaac Vicentini.


Best regards,

Isaac Vicentini
MVP 2025 ✨


If my answer was helpful, mark it as Helpful or Accept as Solution.

View solution in original post

4 REPLIES 4

Isaac Vicentini
Mega Sage

Hi @Yudai Yamamoto!

 

Currently it is not possible using scripts to perform filters in Search Source , see:

 

âž” ServiceNow Docs - Search sources

IsaacVicentini_0-1727889711871.png

 

Alternatively, you can work with ACLs, if the user does not have permission to see a record due to security permissions, it will automatically not appear in the AI ​​Search results.


If my answer helped you in any way, please mark it as Helpful / Accept as Solution 🎯

Regards,

Isaac Vicentini.


Best regards,

Isaac Vicentini
MVP 2025 ✨


If my answer was helpful, mark it as Helpful or Accept as Solution.

jafarhansla
Kilo Contributor

To add a condition using a script for AI Search, you’d typically need to identify the parameters or criteria you want to filter by—like keywords or source types—and implement logic in your script to ensure the search only pulls from relevant sources. For example, if you're searching for 'AI Search' sources related to a specific topic, you'd apply a condition to filter based on that. Speaking of targeted searches, if you're looking for the best Chinese restaurants in Edmonton, you could add a condition to your search to focus on restaurant reviews or specific ratings, helping you narrow down the top spots like The Lingnan or Dynasty Century Palace.

Heverton1
Tera Contributor

I was looking for something like this as well since I need the AI to suggest Knowledge Articles based on the Contact domain.

Dont think this works well for domain separated instances...

leonard_geo
Tera Contributor

Hi Yudai,

it is possible to use inline scripts in search source filters.

 

Create a script include and check your required condition within. 

To use it in the search source filter you need to use some string field of your source table.

For example for business applications you could use the "Portfolio ID" field.

The Portfolio ID of an application is something like APP1234567

 

Search Source:

Condition: Portfolio ID starts with APP 

 

Condition with Script: Portfolio ID starts with javascript:new scope.Your_Script_Include.your_function('allowTerm', 'denyTerm')

 

>> Portfolio ID starts with javascript:new global.ZTAValidation.roleCheck('APP', 'forbidden')

 

Provide the function the values for a allowTerm and a denyTerm. If your script validates to "true" return "APP" as allowTerm. The filter will validate as true and deliver results.
Should the script return "false" return "forbidden" as denyTerm. No results will be shown while searching.

You can use any free text field to use the inlince script validation. This will also work for external content.

 

Hope this helps.