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

Well Robert, that was definitely what needed to happen.   After going the Ajax route it looks like I can finally get the results I am looking for, thank you very much for pointing me in the right direction!



-Brian


Brian Dailey1
Kilo Sage

Hi Brian,



I have a couple of items/questions for you:



  1. What is the name of your list-collector Variable?
  2. Add a line "g_form.addInfoMessage(filterString);" to your client script to see what the contents are in-situ.
    Then copy/paste the results in here.



Thanks,


-Brian