Automation flow help

trivenimaur
Tera Contributor

Hi,

 

I am in learning phase of ServiceNow automation process. Can anyone help how can i run python scripts which kept on mid server or any other server using flow designer.

If there is standard documentation for this please share.

2 REPLIES 2

Srikanth_9
Kilo Sage

Hi @trivenimaur,

 

Could you explain in detail what exactly you are looking for?

Please add screen shots, so that will help you?

 

If the provided solution is useful/working, please Accept as Solution and hit the Helpful. 
 
Thanks & Regards,
Srikanth Akula.

Nishant8
Tera Sage

Hello @trivenimaur, You can use the Integration Hub (the recommended way) to call the Python script easily, but please note that this is a licensed product.
If you aren't using Integration Hub and want to call the .py script, you can create an action in Flow Designer -> add a Script step, and use the script below. 

(function execute(inputs, outputs) {

    //ensure to have \\ instead of \ if using windows for e.g. python installation is C:\\Users\\python.exe and python script is C:\\Users\\python_script.py
	var command = '<path of python.exe> ' +
                  '<python script file>';

    var ecc = new GlideRecord('ecc_queue');
    ecc.initialize();

    ecc.agent = 'mid.server.<Your_Mid_Server_Name>';
    ecc.topic = 'Command';
    ecc.queue = 'output';
    ecc.state = 'ready';
    ecc.name = 'Run Python Script';

    var payload = '<?xml version="1.0" encoding="UTF-8"?>';
    payload += '<parameters>';
    payload += '<parameter name="name" value="' + GlideStringUtil.escapeHTML(command) + '"/>';
    payload += '</parameters>';

    ecc.payload = payload;
    ecc.insert();

})(inputs, outputs);

This script will work if the Python script is placed inside the MID server. If the script is on any other server, that server must be reachable from the MID server (which will work as a jump server).

 

 

Regards,

Nishant