How do I create a custom step that will execute a python script that needs the Job ID as an input to run?

5722
6
Jump to solution
04-09-2015 09:18 AM
deleted-user-7uOyUeQXbkI0
New Contributor III

I've created a python script that I want to run in my workflow.  I figure I need to create a custom executable step and call the python script from that.  The help for creating steps (ArcGIS Help (10.2, 10.2.1, and 10.2.2) mentions that tokens can be used as arguments for the executable.  That sounds great because then I could pass in the Job ID which is the only input that i need for the script to work properly, but how do i get the script to recognize and use the token?

0 Kudos
1 Solution

Accepted Solutions
TopeBello
Occasional Contributor III

The arguments of the step would accept tokens. An example of running this is - Program = c:\Python.exe Arguments = "yourpythonfile.exe [Job:id]". The example is assuming that when you open a cmd line window to run your python script as "yourpythonfile.exe 1"

Alternatively, you could wrap the python script up as a script tool and then use the launch or execute GP tool step to run it and pass in the proper arguments.

I hope this helps!

Thanks

Tope

View solution in original post

6 Replies
TopeBello
Occasional Contributor III

The arguments of the step would accept tokens. An example of running this is - Program = c:\Python.exe Arguments = "yourpythonfile.exe [Job:id]". The example is assuming that when you open a cmd line window to run your python script as "yourpythonfile.exe 1"

Alternatively, you could wrap the python script up as a script tool and then use the launch or execute GP tool step to run it and pass in the proper arguments.

I hope this helps!

Thanks

Tope

deleted-user-7uOyUeQXbkI0
New Contributor III

This helped get me going down the right path.  I was able to use the LaunchGPTool to get it to work properly, but that pops up the Get Parameters GUI (even though it is populating the parameter automatically from the token) and I want this step to run without any input from the user.  Therefore, I switched to ExecuteGPTool and kept all of the same arguments, but it no longer runs the script properly. It is like it isn't getting the JOB_ID parameter now.  Do I need to change my script to not use arcpy.GetParameterAsText in order to use ExecuteGPTool?  I've tried using arcpy.GetParameter and sys.argv, but neither of those worked.

Turns out the above isn't true.  It does work, but not if it is running when the job is created.  The job is set to auto-execute several steps immediately after creation including this step.  The return code for this step though is 1, so failure.  If I reset the workflow to this step and reexecute it, it still says it fails.  If I close and reopen Workflow Manager, and then rerun the step, it completes with success.  I just added in a loop based on failure or success, it just goes to a procedural step that automatically executes and advances and goes back to the step so it can execute again.  I tried creating a new job with this updated workflow and it appears to be stuck in a continuous loop in the job creation.  Because it must be failing over and over.  I killed the application and reopened it and found the workflow at my update step, ran it, and it completed just fine.  Why won't this step complete if it is being executed during the job creation?

Since my original question has been answered, and the issues I am now having are not related to that question. I have created a new discussion for that issue. It can be found at ExecuteGPTool step will not run successfully if auto executed during job creation

0 Kudos
NikhilSai
New Contributor

I tried using above way of passing parameters and tried executing step manually but nothing worked.

Then I gave parameters as below and it did worked 

- Program = c:\Python.exe Arguments = "yourpythonfile.exe" [Job:id]  

JobId should be placed outside the double quote.

0 Kudos
NikhilSai
New Contributor

I tried using above way of passing parameters and tried executing step manually but nothing worked.

Then I gave parameters as below and it did worked 

 

- Program = c:\Python.exe Arguments = "yourpythonfile.exe" [Job:id]  

JobId should be placed outside the double quote.

0 Kudos
deleted-user-59NIbCq7H8Ve
New Contributor II

Hi, make sure the you provide the full path to python.exe and the full path to the python script that you wish to execute.

If you would like to suppress the command window pythonw.exe can also be used.

Hope this helps!

sample arguments for executable step type

by Anonymous User
Not applicable

Thanks Lauren, that's correct.

0 Kudos