---
sourceDocument: Yokohama IT Operations Management
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/yokohama/it-operations-management

 Release :

    - yokohama

ft:locale :

    - en-US

ft:publication_title :

    - Yokohama IT Operations Management

ft:clusterId :

    - itom

bundleId :

    - itom

workflow :

    - Technology


---

# Run DiscoverNow from a script

# Run DiscoverNow from a script {#ariaid-title1}

* Release version: Yokohama
* 
* Updated January 30, 2025
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 1 minute to read

You can run DiscoverNow from a script, such as a background job, a business rule, or
web services.

## Before you begin

Role required: admin

## Procedure

1. Create the following script:  

       var d = new Discovery();
       var statusID = d.discoveryFromIP(TARGET_IP, TARGET_MIDSERVER);

   The discoveryFromIP method takes two arguments:
   <var class="keyword varname">IP</var> and <var class="keyword varname">MID Server</var>. The
   <var class="keyword varname">IP</var> argument is mandatory, but the <var class="keyword varname">MID Server</var> argument is optional.
2. To choose the MID Server, supply either the <var class="keyword varname">sys_id</var> or name of the MID Server as the argument.  
   If you do not name a MID Server, the system attempts to find a valid one automatically. A valid MID Server has a status of Up and can discover the given IP address. If the system finds a valid MID Server and runs a Discovery, the discoveryFromIP method returns the <var class="keyword varname">sys_id</var> of the Discovery status record. If no MID Server can discover this IP address, the method returns the value undefined.

   If you manually specify the
   TARGET_MIDSERVER, the system validates the given value and ensures that the
   MID Server table contains the specified MID Server record. If the validation
   passes, the discoveryFromIP method returns the sys_id of the discovery
   status record. If the validation fails, the method return the value
   undefined.

