- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2019 07:33 AM
Hi Community,
I am trying to create a filter inside of a content block for my dashboards that looks for the letter m at the 10th character from the beginning of the u_resource_pool reference field in the cmdb_ci_vmware_instance table. Contains (like) is too generic of a search for a single character because there could be other unrelated instance where the M letter is contained inside of the entire field (which is long).
I thought the best way to write this would be to use the STARTSWITH argument and then have 9 single character wildcards (which depending on the article are either _ or ? or %) and then the letter m. None of those options worked (code sample below) and I am stumped as to how I can indicate a single character wildcard in my script and could use some assistance.
so basically I want this filter to accomplished the follow
resource pool = 123456789M987654321 - This record would be included in the filter application
resource pool = M123456789987654321 - This record would NOT be included in the filter application
resource pool = 1123456789987654321 - This record would NOT be included in the filter application
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<script>
var my_dashboardMessageHandler = new DashboardMessageHandler("");
</script>
<h2> Select what systems you want to view </h2><br/>
<input id="all_vms" type="button" value="All VM's" onclick="my_dashboardMessageHandler.removeFilter();" />
<input id="only_m_vms" type="button" value="Only M VMs" onclick="my_dashboardMessageHandler.publishFilter('cmdb_ci_vmware_instance','u_resource_poolLIKEm');" /> ##This contains search is not specific enough
<input id="only_m_vmstest" type="button" value="Only M VMs" onclick="my_dashboardMessageHandler.publishFilter('cmdb_ci_vmware_instance', 'u_resource_poolSTARTSWITH%%%%%%%%%m');" /> ##This search does not work
</j:jelly>
Thanks in advance!
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2019 07:52 AM
Hi,
I believe you can utilize indexOf for this. Such as:
current.field.indexOf("m") == 9
This is because the first character counts as 0 and increases from there.
You may also need to use: toLowerCase() to bring everything to lower case or if it's always going to be a capital M...then change out my lowercase m in my example to a capital M.
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2019 07:52 AM
Hi,
I believe you can utilize indexOf for this. Such as:
current.field.indexOf("m") == 9
This is because the first character counts as 0 and increases from there.
You may also need to use: toLowerCase() to bring everything to lower case or if it's always going to be a capital M...then change out my lowercase m in my example to a capital M.
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2019 08:20 AM
Thanks so much for your response @Allen!
it seems like indexof is the correct function but I am struggling to incorporate that function into the mydashboardhandler filter triggered by the button in the content block
I tried these different methods and none of them worked
...
var find_m = current.u_resource_pool.indexOf("m") == 9
...
<input id="only_m_vms1" type="button" value="Only M VMs" onclick="my_dashboardMessageHandler.publishFilter('cmdb_ci_vmware_instance','current.u_resource_pool.indexOf(`m`) == 9');" />
<input id="only_m_vms2" type="button" value="Only M VMs2" onclick="my_dashboardMessageHandler.publishFilter('cmdb_ci_vmware_instance','u_resource_pool.indexOf(`m`) == 9');" />
<input id="only_m_vms" type="button" value="Only M VMs1" onclick="my_dashboardMessageHandler.publishFilter('cmdb_ci_vmware_instance', 'u_resource_poolSTARTSWITH%%%%%%%%%m');" />
<input id="only_m_vms1" type="button" value="Only M VMs 2" onclick="my_dashboardMessageHandler.publishFilter('cmdb_ci_vmware_instance','current.u_resource_pool.indexOf(`m`) == 9');" />
<input id="only_m_vms3" type="button" value="Only M VMs 3" onclick="my_dashboardMessageHandler.publishFilter('cmdb_ci_vmware_instance','find_m');" />
<input id="only_m_vms4" type="button" value="Only M VMs 4" onclick="my_dashboardMessageHandler.publishFilter('cmdb_ci_vmware_instance',find_m);" />
...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2019 10:44 AM
The only available operators are listed here: https://docs.servicenow.com/bundle/london-platform-user-interface/page/use/common-ui-elements/refere...
There may be other operators, but if they are listed here, they aren't documented or supported, so be wary. I don't see what you are looking for.
What I would do is a scripted filter to search the reference table, get the sys_ids from those and then use that for the query. Check out this article for some examples: https://community.servicenow.com/community?id=community_blog&sys_id=bd0eaa2ddbd0dbc01dcaf3231f96199e
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2019 11:02 AM
Thanks Adam,
After taking a break and coming back to this I realized that I made this much more complicated than it needed to be, and I may have had the correct answer and just have been dealing with a bug.
What I need to figure out is how to include a single character wildcards in my dashboardmessagehander filter. I'm trying to figure out if it's a bug in our servicenow instance or my poor coding skills at the moment.
In theory Should this filter below return only records whose 10th character in the u_resource_pool field is M or did I write the encoded query wrong? (ps we are running kingston at the moment)
<input id="only_m_vms" type="button" value="Only M VMs1" onclick="my_dashboardMessageHandler.publishFilter('cmdb_ci_vmware_instance', 'u_resource_poolSTARTSWITH%%%%%%%%%m');" />