How to Run a Quick discovery from run script in workflow

supareub
Tera Contributor

I'm trying to Take IP address as input from user in Service catalog and pass it into script which i created in action of flow designer to run a quick discovery. If Device is discovered, i want discovery information (IP Address, Device Name, Class, URL to Discovery CI) in return. Till now i have able to run discovery script and get statusid in return but not able to get discovery information.I have added my code below.Can anyone help?

6 REPLIES 6

Saurabh Gupta
Kilo Patron
Kilo Patron

If you are able to run the quick discovery then you should use a wait for condition until this quick discovery finishes.

 

PFA the status record, your flow should wait it is comepleted

 

SaurabhGupta_0-1672044827852.png

 

Once this is completed, try fetch the ci detail.

SaurabhGupta_1-1672044889514.png

 

 

 

 

 


Thanks and Regards,

Saurabh Gupta

Whenever i run script i am getting sys id for discovery record, but state always is canceled, Can you please tell how should i use wait for in below script.

After the execution of the attached script.

Get the sys_id of Discovery Status record.

After this you need to lookup discovery_status table with the sys_id=from previous step.

 

And Apply the wait for condition here to state as Completed.

 

 

 


Thanks and Regards,

Saurabh Gupta

Gunjan Kiratkar
Kilo Patron
Kilo Patron

Hi @supareub ,

To run a quick discovery from a script in a workflow in ServiceNow, you can use the new DiscoveryQuickScan() method. This method returns an instance of the DiscoveryQuickScan class, which you can use to specify the target IP addresses or network ranges to scan, and to start and stop the scan.

Here is an example of how you can use this method in a script step in a workflow:

// Create a new DiscoveryQuickScan object
var scan = new DiscoveryQuickScan();

// Set the target IP addresses or network ranges to scan
scan.setTargets("10.0.0.0/8");

// Start the scan
scan.startScan();

// Wait for the scan to complete
gs.sleep(30000); // wait 30 seconds

// Stop the scan
scan.stopScan();

 

This example creates a new DiscoveryQuickScan object, sets the target IP addresses or network ranges to scan, starts the scan, waits for 30 seconds, and then stops the scan. You can adjust the wait time to suit your needs, or use a loop to check the status of the scan and wait until it has completed.


Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy