Triggering External Script on creation of an ticket or incident in service now
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-25-2015 06:23 AM
Is there any option to invoke or trigger an external custom shell or python script on creation of an ticket or incident in service now.
Also, sysid or incident number should be passed as input parameter to the script.
How do we achieve this in service now?
-Madan

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-25-2015 06:26 AM
There are a number of ways to achieve something like this. You can use orchestration to run powershell or web services to integrate with another system.
Python Web Services Client Examples - ServiceNow Wiki
Web Services - ServiceNow Wiki
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-25-2015 07:20 AM
We have implemented something like this:
1) Set up a MID Server on the server where you want to execute the command. To the best of my knowledge you do not need any special license (Discovery or Orchestration) to do this. The ID running the MID Server must be credentialed to run your local script
2) Create a ScriptINclude or Business Rule that contains logic that will create entries in the ECC queue. The command you want to execute will be placed in the name field
Here is some sample code where we pass along a new Status value to a script to update SmartsINCharge :
var egr = new GlideRecord("ecc_queue");
egr.initialize();
egr.agent = "mid.server." + this.midServer;
egr.queue = "output";
egr.topic = "Command";
// build the TEC command
egr.name = /opt/patrol/release/SAM/smarts/local/script/ic-update-from-TT-SN.sh INC000003766544 "Resolved" "Closed"
egr.insert();
Hope this helps.
Sandy

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-08-2018 05:32 AM
Hi SandySeegers. Looking at the script you posted, what does the insert do? Is this a script include part? How would you suggest I do a process like this.
1. Run a python script in MID-Server.
2. The Python Script will take in input parameter from SN to extract the data needed.
3. The Python Script will need to return the queried record back to SN for further processing.
BTW, can you share the content of the /opt/patrol/release/SAM/smarts/local/script/ic-update-from-TT-SN.sh you posted to help me get better understanding of what is happening?
Respectfully,
Randy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-08-2018 06:59 AM
Randy,
When a MID Server is active, it continuously queries the ECC queue for 'Output' records directed towards it. When you create a record in ECC queue with your MID server tagged and the Topic is 'Command' it executes the command it finds in the name field. The results of the command are then returned by the MID server in the form of an 'Input' record in the ECC queue table. I believe the Command field of the response Input record matches.
egr.agent <-- This is 'mid.server.' + the name from your midserver record.
egr.queue <- "output" Your MID Server looks for output records to consume
egr.topic <- "Command" tells your mid server to execute what it finds in the name field
egr.name <- The command to execute. This would be the execution of your local python script with any needed input parms. (note: I have zero Python experience)
Unfortunately, I don't have access to the script any more so I can help you there. My advice is to keep it simple. Execute your script from a command line on your local MID Server host. What you type in the command line is what you want your script to write to the name field on the command record you create in ECC. Note the response you get when you manually enter the command on your local host. That's what will be in the response input record in ECC.
Hope this helps
Sandy