Page 1 of 1

import reusable function from another snippet/python?

Posted: Tue Sep 06, 2022 2:21 pm
by toddsou
Hi-

I have several snippets where they all do a similar thing, and so it occurred to me that I should refactor the code such that the reusable part can be called by all of them where they would simply pass a parameter for each caller to achieve its desired affect on the Order.

A's snippet:
Call R.DoThatThing(1);

B's snippet:
Call R.DoThatThing(2);

C's snippet:
Call R.DoThatThing(3);

R's snippet:
Define function DoThatThing(i) where maybe it adds an Order Note with a message including parameter i;


While it is straight forward to do this in Python via import, I'm not sure how to do this within the SPS automation snippet environment.

Thoughts?

Re: import reusable function from another snippet/python?

Posted: Wed Sep 07, 2022 10:28 am
by BobRichards
We do not required that Python is installed on the customer's systems (neither client nor server) because of possible incompatibilities. Because of this, most standard Python import libraries are not available. We only support imports of the SoftPro libraries and .NET libraries available from the GAC. This makes the Python libraries (strictly speaking) unnecessary.

Using imports the way you want makes total sense - but it is not recommended. Snippets can be run on any server instance so while the snippet code is maintained on the server and downloaded to the instance as needed, the import files will not be downloaded and must be accessible from all servers.