- 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-07-2018 10:31 PM
Hi Sid,
I have created a service catalog with the following fields:
(Enter Hostname : hostname,
Enter IP Address : ip_address,
Tags for IP Address : tags_name)
Below is my onChange Client script that changes the filter of List collector based on the value in ip_address field:
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();
window[collectorName + 'g_filter'].setQuery("u_ip_address=" + g_form.getValue("ip_address"));
window[collectorName + 'acRequest'](null);
}
Please change the variable name as per your service catalog and you don't need to call any server side script. Also I think(not 100% sure) regex will not work in server script and will stop your server script in between.
I have also created a Mapping table with below fields:
Please mark this solution correct, if it resolves your problem.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-09-2018 08:25 AM
Mahi,
This is going to show tags that have the exact same IP as one entered by user. I need to show tags within the same range. From the example you showed above, I want to be able to show all the tags in range of 10. network once the user starts to enter IP.
From your example above I would like all those tags to display in the collector since they are all in "10." range, but if there were any "192." or "172.16." addresses then it should not show.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-09-2018 09:14 AM
okay.
so now I want to know that 10. will be at the start of IP address or at any position? Also I want to know that 192. or 172.16 these will also be at the start of IP address or can be any where in IP Address?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-09-2018 09:26 AM
Yes, it will be at the begining of the string. example, 10.x.x.x, 192.168.x.x, 172.16.x.x. It will always be at the beginning of address.