Why is a query string which works fine when I put it in via browser URL not working when being called from a catalog client script?

bcronrath
Kilo Guru

Using the following type of URL as an example:  

https://[SN instance]/sys_user_list.do?sysparm_query=sys_idINjavascript:funcThatReturnsUserIdsCommaDelim(%27[test company sys_id here]%27).toString()

I am using this guide more or less as a template:   Changing the Filter of a List Collector Variable via Client Script - ServiceNow Guru In order to set the user list of a watch list list collector on a form to provide a list of users that matches the set of IDs returned by the funcThatReturnsUserIdsCommaDelim function.

When I use that url with the query parameters above I get the expected set of results back.   However when using the same style of query:

filterString = 'sys_idINjavascript:funcThatReturnsUserIdsCommaDelim (\'' + g_form.getValue('u_company') + '\').toString()';

And later on the query is applied to g_filter:

eval(collectorName + 'g_filter.setQuery("' + filterString + '")');

It doesn't work, it just keeps giving me nothing back on the list collector.   Even though when I look at the js web console in my browser it *seems* that it should be getting called correctly:

setQuery Synchronously:   sys_idINjavascript:funcThatReturnsUserIdsCommaDelim('[Same sys_id as from above]').toString()

It's putting the right company sys_id in and everything yet I'm not getting a result set returned.   The list collector is set as follows:

find_real_file.png

For the record, I was able to get earlier tests to run just fine with a much more simple filterString of:

filterString = 'company=' + g_form.getValue('u_company')

This would give me back a list of users that had a u_company value (just a field that references the core_company table) properly. This however doesn't work for our needs since we use a many to many user and company lookup table, so hence why I'm using a function to return a list of sys_user sys_id values comma delimited.   I've verified this function works properly when passed in a company sys_id via both fix scripts with debugging outputs, and in that first url I posted which uses query parameters.

I'm currently at a loss as to why I can't get the function to work through this catalog client script.   I've tried using double quotes and url encoded character codes such as the %27 as well but neither works.

Best regards,

Brian

1 ACCEPTED SOLUTION

I have something very similar to this working well on a List Collector. Where is the function that you are trying to call to return your sys_ids declared? Is it in a Script Include that you are trying to access from a client script? If so, you would need to GlideAjax (GlideAjax - ServiceNow Wiki) if you want to access server-side code from a client script. Have you tried displaying the results of your function in an alert or dev console to make sure it is returning what you expect?


View solution in original post

6 REPLIES 6

bcronrath
Kilo Guru

I should also note that if I remove the attribute of no_filter from the list collector, the filter looks exactly the same when comparing it and the URL query to sys_user_list.do, which further confuses me as to why they are behaving differently.


bcronrath
Kilo Guru

I should also note I'm open to alternative suggestions for how to filter here, it would appear at least that the same way a url can use filter parameters is not the same way a list collector can.


bcronrath
Kilo Guru

Pinging this again and really hoping someone might know a solution to my issue.   To simplify the issue - I have a content page with a CC list collector that should be collecting from the user table, and I have enabled a filter on it to show that my filter is exactly the same as I would put into the Users table yet I am getting no results on the cc list collector.



find_real_file.png


Where "sysIdHere" is sanitized in the screenshot but is a proper sys id for what the function expects.   If I put the same exact filter on the Users tables, I get back the results I am expecting, a list of users instead of nothing:


find_real_file.png


find_real_file.png


Is Javascript not callable from a content page or something?   I'm having no luck figuring this one out.


I have something very similar to this working well on a List Collector. Where is the function that you are trying to call to return your sys_ids declared? Is it in a Script Include that you are trying to access from a client script? If so, you would need to GlideAjax (GlideAjax - ServiceNow Wiki) if you want to access server-side code from a client script. Have you tried displaying the results of your function in an alert or dev console to make sure it is returning what you expect?