Run DiscoverNow from a script using multiple IP addressesIssue <!-- div.margin{ padding: 10px 40px 40px 30px; } table.tocTable{ border: 1px solid; border-color:#E0E0E0; background-color: rgb(245, 245, 245); padding-top: .6em; padding-bottom: .6em; padding-left: .9em; padding-right: .6em; } table.noteTable{ border:1px solid; border-color:#E0E0E0; background-color: rgb(245, 245, 245); width: 100%; border-spacing:2; } table.internaltable { white-space:nowrap; text-align:left; border-width: 1px; border-collapse: collapse; font-size:14px; width: 85%; } table.internaltable th { border-width: 1px; padding: 5px; border-style: solid; border-color: rgb(245, 245, 245); background-color: rgb(245, 245, 245); } table.internaltable td { border-width: 1px; padding: 5px; border-style: solid; border-color: #E0E0E0; color: #000000; } .title { color: #D1232B; font-weight:normal; font-size:28px; } h1{ color: #D1232B; font-weight:normal; font-size:21px; margin-bottom:-5px } h2{ color: #646464; font-weight:bold; font-size:18px; } h3{ color: #000000; font-weight:BOLD; font-size:16px; text-decoration:underline; } h4{ color: #646464; font-weight:BOLD; font-size:15px; text-decoration:; } h5{ color: #000000; font-weight:BOLD; font-size:13px; text-decoration:; } h6{ color: #000000; font-weight:BOLD; font-size:14px; text-decoration:; } --> Run DiscoverNow from a script using multiple IP addresses Background In ServiceNow Product Documentation, the following article, Run DiscoverNow from a Script, describes the basic process of running DiscoverNow from a script. However, customers who are required to run this script and also require the ability to enter multiple IP addresses, are unable to get the process to work correctly. When reviewing the code, we noticed that all of the variables were defined globally, so we suggest that the code be encapsulated in a function. This resolves the issue. When using short variables such as d (as seen in the following script example), and defining the variable globally, it is very easy for the variable to be overwritten if another script is also using a globally defined variable called d, elsewhere on the system. Encapsulating the code within a function fences off the variables, which are defined locally and can not be re-defined outside of that function. The next section provides an example for customers who may require the same functionality. Example Script function RunMyDiscoverNow() { //Enter the IP Adresses in the Array IPAdresses, and comma seperate //Example: "x.x.x.1, x.x.x.2, x.x.x.3" var IPAdresses = "10.200.218.27, 10.200.218.99, 10.200.218.191"; var iparray = IPAdresses.split(","); for (var i=0; i < iparray.length; i++) { var ipaddr = iparray[i] //Ensure that a valid MID server name is used as the //2nd parameter to d.discoveryFromIP var d = new Discovery(); var statusID = d.discoveryFromIP(ipaddr,'MIDSERVER1'); gs.print("This is the address that was scanned " +ipaddr); } } RunMyDiscoverNow();