Skip to main content
Nintex Community Menu Bar
Solved

How to user Parameters field in Run Script command

  • Feb 28, 2024 7:21 PM UTC
  • 6 replies
  • 222 views
  • Translate All

Forum|alt.badge.img+2

Does anyone know how to use Parameters field in Run Script command? If I have, say, a python code as in the picture, how do I pass “testInputVariable” into the code to be used as variable a of function testFunction?

Best answer by bsikes

Maybe try sys.argv[1] instead?  I’m not entirely sure how Nintex RPA is executing the scripts. 

View original

6 replies

Forum|alt.badge.img+11
  • Contributor
  • Feb 29, 2024 5:35 PM UTC

@Alisher SV Do you have a need to actually pass the variable as a parameter into the script, or can you just use the variable within the script, without any parameters?

def testFunction(a):
return a


b = testFunction($testInputVariable$)

print(b)

 

Disclaimer: I’ve never done anything with Python. 

Translate

Forum|alt.badge.img+2
  • Author
  • Rookie
  • Feb 29, 2024 6:52 PM UTC

Thank you @bsikes.

The way you showed is the way I do it now and it works.

Yet, I would like to learn how to use Parameters fields because it would allow me to keep the code and input variables separately. 

Translate

Forum|alt.badge.img+11
  • Contributor
  • Feb 29, 2024 7:09 PM UTC

Do you know how you would pass parameters to a python script outside of Nintex, such as from a command prompt window?  It’s probably very similar. 

https://stackoverflow.com/questions/22846858/python-pass-arguments-to-a-script

 

That makes me think you’d need to include this to access, as example, the first parameter passed to the script:

import sys

firstParameter = sys.argv[0]

 

Translate

Forum|alt.badge.img+2
  • Author
  • Rookie
  • Mar 1, 2024 4:10 PM UTC

Yes, parameters are passed to python function as indicated in your response. 

I tried your recommendation and instead of input variable, it is returning the path to a temp file.

 

Translate

Forum|alt.badge.img+11
  • Contributor
  • Answer
  • Mar 1, 2024 4:12 PM UTC

Maybe try sys.argv[1] instead?  I’m not entirely sure how Nintex RPA is executing the scripts. 

Translate

Forum|alt.badge.img+2
  • Author
  • Rookie
  • Mar 1, 2024 4:24 PM UTC

It did not work with sys.argv[1], but worked with sys.argv[2]. 

So, to access parameter 1,  sys.argv[2] needs to used, for parameter 2  sys.argv[3], … so on so forth.

Thanks a lot @bsikes, this answers my question. I wish Nintex website provided these details. 

Translate