- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2018 03:39 PM
Hello all,
I'm really hoping I can get some help/solution on this as its not working and I am a bit lost on how to make it work given I'm a servicenow newbie.
I have a catalog item with fields for Hostname and IP, and a list collector which shows currently available Tags. Currently the user is able to select any number of tags that are being shown in the list collector. Now, I have a table setup, lets call it mapping table, which has records of IP address ranges associated to certain tags. What i want to do is once the user puts in the IP address, the list collector should filter and only show tags it finds associated to that IP range in the mapping table. For example, if user puts 10.0.0.1, the list collector should update and only list tags which are associated to that range in table. similarly if user puts 192.168. address it should show tags related to that range.
I did some research and found onChange with include script would be the best way to achieve this, I have the following script but when i open the catalog item it does not update anything. I only have the regex for 10.x.x.x address in script for now, plan on adding 192.168 and 172. regex once this is functional.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2018 09:45 AM
okay
In my case I have a table where I have stored IP Address and Corresponding tags for those IP Address as shown in above image. you can ping the screenshot of your table so that I can understand it in a better way.
If the string is in begining then use the below code:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === ''){
return;
}
var collectorName = 'tags_name';
alert(g_form.getValue('ip_address'));
window[collectorName + 'g_filter'].reset();
if(g_form.getValue("ip_address").startsWith("10."))
window[collectorName + 'g_filter'].setQuery("u_ip_addressSTARTSWITH10.");
else if(g_form.getValue("ip_address").startsWith("192."))
window[collectorName + 'g_filter'].setQuery("u_ip_addressSTARTSWITH192.");
else if(g_form.getValue("ip_address").startsWith("172.16"))
window[collectorName + 'g_filter'].setQuery("u_ip_addressSTARTSWITH172.16");
window[collectorName + 'acRequest'](null);
}
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2018 09:34 AM
Also, based on your script it would work if the list collector is based off the mapping table containing the tag and associated IP address correct? in my scenario, the Tags are stored in a separate table which is being referenced by the list collector.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2018 09:45 AM
okay
In my case I have a table where I have stored IP Address and Corresponding tags for those IP Address as shown in above image. you can ping the screenshot of your table so that I can understand it in a better way.
If the string is in begining then use the below code:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === ''){
return;
}
var collectorName = 'tags_name';
alert(g_form.getValue('ip_address'));
window[collectorName + 'g_filter'].reset();
if(g_form.getValue("ip_address").startsWith("10."))
window[collectorName + 'g_filter'].setQuery("u_ip_addressSTARTSWITH10.");
else if(g_form.getValue("ip_address").startsWith("192."))
window[collectorName + 'g_filter'].setQuery("u_ip_addressSTARTSWITH192.");
else if(g_form.getValue("ip_address").startsWith("172.16"))
window[collectorName + 'g_filter'].setQuery("u_ip_addressSTARTSWITH172.16");
window[collectorName + 'acRequest'](null);
}
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2018 10:42 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2018 08:57 PM
Okay.. Please call on 9833622526 once.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2018 01:05 PM
**Resolved**
For those who may encounter a similar scenario.
I was able to get it to work by changing the code a bit from Mahi9315's response. I called the list collector variable directly instead of going through variable. My list collector is named 'Tags'
var ipValue = g_form.getValue('IP_Address');
filterString1 = "<field_name> STARTSWITH10"
Tagsg_filter.reset();
if(ipValue.startsWith("10.")){
Tagsg_filter.setQuery(filterString1);
} else{
..add code..
}
TagsacRequest(null);
this successfully got the list collector to filter results upon change on IP address field.