How to pass javascript function into query Business rule?

swathigangadhar
Tera Expert

Hi,

Thanks in adv,

I have an issue regarding Query business rule, while i am trying to do query business rule to query the records its not retrieving.

here i am using below script include to retrieve the array of sysids.

fd.png

I am calling this script iclude in a query business rule as shown below to query the records.

current.addEncodedQuery("sys_id=javascript:AssetAccess()");

tedsdtd.png

but its not working,Please help me out where i am missing.

8 REPLIES 8

I don't understand your AssetAccess function.



As Chuck pointed out, it currently will only return a list of the same sys_id.



And you're returning every user that has a group? I don't understand this.



What is the business problem you are trying to solve?



ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

the business problem is different and it is in asset.



Generally if we use encodedquery by using 'sys_idIN'_AssetAccess(); then it retriving and working fine, but while opening a record the URL will shown as below.



https://devxxxx.service-now.com/sys_user_group.do?sys_id=b85d44954a3623120004689b2d5dd60a&sysparm_re...



If it is retrieving 1000 sysids it crosses the limitation which is not suggestible.



So we are passing this as a function then while opening the record the url have only the function   name which is in bold irrespective of sysids as shown below.



https://dev22331.service-now.com/sys_user_group.do?sys_id=b85d44954a3623120004689b2d5dd60a&sysparm_r...sys_id%3Djavascript%3AAssetAccess%28%29++++++++%5EORDERBYname



so how to retrieve sysids using a javascript function.


This is a limitation that I'm not sure we can get around.



Alas, if I understand your business problem, I can try to give an alternative solution that has the same business outcome.



Who is supposed to have Asset Access? And what is the requirement around visibility to groups?


We might be able to come up with a smaller query, or an alternative (such as ACL's).



ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

ACL's we are not using, since there are many restrictions.



Business problem is same as i described above, same for asset.


Who is supposed to have Asset Access? :All users, but he should be able to see assets belong to his location.