louisphicc
Member
Hello List!
So I was struggling to run some Python scripts from the Orchestrator...
I finally got it right and I thought I could share the general method with you.
I have (so far) 2 use cases for this :
That's all.
I hope you find it usefull and please share your use cases if any!
So I was struggling to run some Python scripts from the Orchestrator...
I finally got it right and I thought I could share the general method with you.
I have (so far) 2 use cases for this :
- Format the csv output from a JDE Report into a *.xlsx file.
- Communicate with Sharepoint (download/upload and read files).
- Download and install Python 3.xx on your AIS server (https://www.python.org/downloads/). In my case, my AIS server is running under Windows Server 2016 and the installation had to be done for all users using the "custom install" feature. I also manually chose the install folder as C:\Programs\Python\. This is important for later, in the Groovy code below.
- Pip install any library you want to use in your scripts. To manipulate CSV into Excel files, I used openpyxl (https://openpyxl.readthedocs.io/en/stable/). To communicate with Sharepoint, I used Office365-REST-Python-Client.
- Make sure that all users have access to the Python installation folder (C:\Programs\Python\ in my case).
Java:
import com.oracle.e1.common.OrchestrationAttributes;
import java.text.SimpleDateFormat;
HashMap<String, Object> main(OrchestrationAttributes orchAttr, HashMap inputMap)
{
HashMap<String, Object> returnMap = new HashMap<String, Object>();
// 2 strings to get the command output and error message
def cmd_out = new StringBuilder();
def cmd_err = new StringBuilder();
// The command to execute
cmd = ['C:/Programs/Python/Python.exe', 'C:/MyScript.py', 'arg1', 'arg2'];
// Execution
def proc = cmd.execute();
proc.consumeProcessOutput(cmd_out, cmd_err);
// To wait until the command is done
proc.waitFor();
// Return the command outputs
returnMap.put("command_output", cmd_out);
returnMap.put("error_message", cmd_err);
return returnMap;
}
That's all.
I hope you find it usefull and please share your use cases if any!