javascript list filter

stefan30
Kilo Explorer

Hello All
For reporting purposes we want to use a business rule to populate a filter.
Unfortunately we can't get it to work. This is what's happening:
We have created the following global business rule (client callable):
function testFilter() {
return "test^companyISNOTEMPTY";
}
When we go to task.list and select the field [ short_description] , IS , javascript:testFilter();
the business rule is called and the filter is populated with the string "test^companyISNOTEMPTY ".
However the system does not compile the string to the fields properly.
When we copy past the string directly in the filter the string gets separated to multiple fields like we expect:
[short_description'], IS , 'test^companyISNOTEMPTY' the string is compiled in to the following:
[short_description] , IS , "test"
[ Company] , ' is not empty"
If you can tell me what we should do to make the string from the business rule suitable for the filter, please let me know.
Regards, Stefan

3 REPLIES 3

john_andersen
Tera Guru

I have never tried what you are doing, but I wonder if it wouldn't be easier to just call the filter for your list using URL parameters?

URL filter or query parameters are in the format of:
sysparm_query=caller_id%3D46c6f9efa9fe198101ddf5eed9adf6e7%5Epriority%3E3

So this link...
https://demo.service-now.com/incident_list.do?sysparm_query=caller_id%3D46c6f9efa9fe198101ddf5eed9adf6e7%5Epriority%3E3
...will return a filtered incident list on a specific caller with a priority greather than 3.

More info on how to get the query string you want can be found here:
http://wiki.service-now.com/index.php?title=Embedded:Encoded_Query_Strings#Generating_Encoded_Query_Strings_through_a_Filter

If you still have the requirement to use a Business Rule to generate a filter on the fly, then I'll let other people respond that have experience in this. I just wanted to make sure you were aware of the URL parameters that are available.


Hello John,
Thank you for your reply,

We want to use this in a list report. We would like to give some variables to the report but this method (stored in different tables, which will be calculated by the business rule). The report will be used in a dashboard (homepage) and should show different values for different people using that homepage. I do not see how we can manage this by using URL.
Hopefully your contacts have any idea how to solve this issue.

Regards,

Stefan


millebre
Kilo Contributor

How are you going to use this? In a list view of a table, or only on a report (which may be a list report)?

It doesn't look like forcing multiple query pieces through a single condition field works the way you want to use it. I think you could use one function (probably best to use a script include vs a global business rule) for each actual value, and then set the operator with the builder itself. Then, save the report (or filter if not a report). Just make sure your functions are returning exactly what you would type in if you were doing it without the function.

The screen would look something like this:
[Short Description] | is | javascript:testFilterSD()
[Company] | is not empty
[Close Notes] | is | javascript:testFilterCN()
[Assigned To] | is not | javascript:gs.getUserID()