Solved

How to user Parameters field in Run Script command

  • 28 February 2024
  • 6 replies
  • 56 views

Badge +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?

icon

Best answer by bsikes 1 March 2024, 17:12

View original

6 replies

Userlevel 4
Badge +10

@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. 

Badge +2

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. 

Userlevel 4
Badge +10

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]

 

Badge +2

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.

 

Userlevel 4
Badge +10

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

Badge +2

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. 

Reply