Overview

Aqtra Platform provides the ability to use Python for multiple purposes as a convenient widely known scripting/programming language.

Python scripts supported by Aqtra Platform need to use version 3.0 of Python as described here: https://docs.python.org/3/. A full developer’s guide can be found at Python Developer’s Guide.

The version of Python that Aqtra Platform uses is Iron Python which provides an interface to C# code. It provides two important libraries that need to be imported at the start of a script - clr and system. These libraries provide access to Aqtra Platform’s entities that can be queried and controlled from inside the script.

Multiple ways to use Python scripts in Aqtra Platform

There are multiple ways to use Python in the Aqtra Platform:

  1. As part of Component Script which is a part of any Component. It allows controlling application forms designed and executed using Aqtra Platform, as well as providing custom subscripts that can be run as a reaction to some event, such as a customer pressing a button. There are 3 main ways Python code is used in Component Script
    1. The general part of Component Script that is executed each time a component form is rendered
    2. Calling function inside Component Script on for example a button press event
      1. To do that, you need to define a function inside Component Script, and then go to your UI control such as Button, go to Actions section, and set Command Type to Execute Script. Then you need to put the name and call parameters (if any) of your script into the provided fields
    3. Using function inside Component Script for on value change events
      1. To do that, you need to define a function inside Component Script, and then go to your UI control such as text box, etc, then go to the Events section, and input the name of your script into the On Value Change field
      2. Please note that this function will only be called if field data has changed, and the UI control focus in the form will be switched off this UI control
    4. By subscribing to the changes in data using context.DataModel.Model.Subscribe() method
      1. The simplest way to do this is to define a catch-all changes function (e.g. def check_all_changes()) in your Component Script, and then subscribe to it
      2. Your function will be called every time there is a change in current UI control data, at the moment this UI control will lose focus (e.g. user switches to a different UI control or another application)
  2. As part of the DataFlow activity Execute Script for defining decision & data transformation logic and establishing internal variables to be used as part of DataFlow scenarios. You can see examples of using Python script for DataFlow in our Tutorial #2.

Using Python to access Aqtra Platform components

To access Aqtra Platform components, first IronPython library clr needs to imported as shown below in italic.

#Add IronPython library that imports system CRL (.NET) names into Python

import clr

Once imported, multiple entities can then be accessed from inside of a Python script via ‘context’ variable.

Using context.Model & context.DataModel

context.Model & context.DataModel provides access to various data fields of the Aqtra Platform component model.

For context.Model, data fields include both default component fields provided by Aqtra Platform, as well as custom fields added by the component developer.

For context.DataModel, only custom fields added by component developers are accessible.

It is recommended that context.DataModel is used for accessing all custom fields, and context.Model is only used to access default internal component fields.

For example, see the screenshot below that shows the data model for Tutorial #1.