Get Started with Python 3 Script

Python is a dynamic programming language that is freely available and easy to learn.

Orchid has implemented PYTHON 3 scripting around the Sage 300 Views and Sage 300 desktop screens, so site specific business logic can be implemented using PYTHON 3 scripting and applied to Sage 300 core and 3rd Party Views (if they are developed in the Sage 300 SDK) – when records are inserted, updated and deleted.

Useful Resources

Google “PYTHON 3 Tutorials” and you will find many sites. Some useful ones are

https://wiki.Python.org/moin/BeginnersGuide

https://www.Python.org/about/gettingstarted

http://www.Python-course.eu/Python3_course.php

Sample scripts

Sample PYTHON 3 scripts from Orchid are installed in the VIXXA\Scripts folder of the directory where Sage 300 is installed.

Importing Python libraries/packages in a script

Some Python libraries are installed with the Extender install. You can then import them in an Extender script.

If you want to use a Python library that is not installed with the Extender install, you can add the following line #@ pip(libraryname) to the script that requires the library.

How does it work?

Behind the scenes, the first time a user runs a script, if the library isn't installed on the machine, Extender downloads the scripts from the database as they are cached for performance reasons. If a script includes @pip, Extender also downloads the required Python packages in the user's temp directory, %LOCALAPPDATA%\COMPANY\{orgid}\scripts\python388\site-packages folder. (or python folder if you use the Python 3.4 version).

To do this, Extender runs @pip and python.exe, which displays the cmd prompt pop-up the first time a user runs the screen. This should only happen once for each network user.

If you delete the files in that folder, they will be downloaded again next time the script runs.

Tip: This feature applies to all scripts, including screen scripts.

Example:

If you need to use the requests library, add a comment line #@ pip(libraryname)

Copy

Install library

#@ pip(requests)
Note:

Some packages are not compatible with Extender, for example numpy and pandas won't work in Extender scripts.

The issue is that numpy does not work with sub-interpreters correctly (see https://lists.archive.carbon60.com/python/dev/1406603). There is nothing Extender can do about that .

Troubleshooting using Online debugging tool

You can use https://www.onlinegdb.com/online_python_debugger to help troubleshoot scripts. It helps identify Python related issues (but it's not specific to Sage 300).

This is particularly useful when you get an error loading a script in Extender Setup > Scripts.

Select the script with an error in your preferred Text Editor, Copy to the clipboard and Paste in the Python Editor. If the script has a syntax error, such as wrong indentation, it will point to the line with the error.

Even with a valid script, you will see errors relating to the accpac.py - You can ignore such errors.

See Also

Tips to get started with Extender scripts

Getting Started with Extender