Using Python¶
Introduction¶
The platform provides the ability to use Python for various purposes, due to its convenience and wide adoption as a scripting and programming language. Python scripts on the platform must comply with version 3.0 as described in official Python documentation. The full Developer's Guide is available in Python Developer's Guide.
Python on the platform is called IronPython, which enables interaction with C# code. It includes two main libraries - clr
and system
, which provide access to platform entities.
Python Library Menu¶
In this menu, you can add common Python modules that become available on the front-end (in Component Script) and on the back-end (in the Execute Script step for dataflow).
Viewing Common Python Modules¶
The Python Modules Menu displays a list of modules that have already been added, including information about whether the module is available for front-end, back-end, or both.
Adding a New Module¶
When you click on the Add button, the window for adding a new module opens.
In this window, you can:
- Select the availability type of the new module (front-end, back-end, or both).
- Specify the name of the new module to import.
- Insert and verify the module code through "Compile".
Platform and Python¶
Python can be used as part of the Component Script for each component, allowing you to control the forms of applications, as well as part of the Dataflow via the Execute Script step.
Functions can be called in a variety of ways, such as one of the UI controls when certain events occur.
To access platform components, you need to import IronPython libraries (clr
and system
) and use the context
system variable.
context.Model
& context.DataModel
¶
context. Model
& `context. DataModel' provide access to various data fields in the Platform model.- It is recommended to use
context.DataModel
to access custom fields andcontext.Model
to access the component's default internal fields.
context.Properties
¶
`context. Properties' allows you to control UI controls, such as changing their visibility or availability. Example:
context.Properties.
context.Form
¶
context.Form
is used to access form data or manage the visual representation of the form, for example, to set error messages. Available functions:
- `context. Form.Get(). SetValue()' - Sets the value for a specific UI control in the current form.
- `context. Form.Get(). AddError()' - Sets the error message displayed below a specific UI control in the current form.
- `context. Form.Get(). ClearError()' - Clears the error message displayed under a specific UI control in the current form.
Example:
Python | |
---|---|
context.Commands
¶
`context. Commands' can be used to control the user interface of a currently executable component, change the content of the current form, open different pages, open new components, return to the previous page, or even launch new Workflows, Dataflows, or Scripts.
Examples of available functions of context.Commands:
- `context. Commands.AddItem (GUID)': Add a UI control to a page using a GUID.
- `context. Commands.ChangePageAsync (GUID)': Open the page using its GUID.
- `context. Commands.ChangePageByName("PageName")': Change the current component page to a new page using the internal name.
- `context. Commands.OpenComponent (GUID ComponentID, GUID PageID)': Open a new component and a specific page inside the component.
- `context. Commands.EditItem (GUID UI_ControlID, EntityId)': Shifts the focus of the UI to a specific UI control and specific data (using its internal ID).
- `context. Commands.ExecuteWorkflow (GUID WorkflowID)': Execute a workflow using its ID.
- `context. Commands.ExecuteDataflow (GUID DataflowID, ContextID)': Execute dataflow using its GUID and the specified data context.
context.Commands.ExecuteScript ("ScriptName", "ScriptParams")
: Execute a script (function) from Component Script with some parameters.
context.Logger
¶
Functions from ‘context. Logger’ allow you to write information from the Component Script to the browser console.
The current version of ‘context. Logger’ includes the following methods, which differ in how the corresponding messages are displayed in the browser console (e.g. Info - black, Error - red, etc.):
- 'context.Logger.Info(String)': Writes an information message to the browser console.
- `context. Logger.Error(String)': Writes an error message to the browser console.
- `context. Logger.Trace(String)': Writes a trace message to the browser console.
- `context. Logger.Error(Exception, String)': Writes the error message and exception information to the browser console.
Example of a function from Component Script that outputs the string "Show model info" and the field value 'Property_1':
Python | |
---|---|
context.PlatformServices
¶
Updated to version 0.7.0
The functions of 'context. PlatformServices' include a wide range of functions available on various platforms (web, mobile), as well as functions for building and displaying modal windows and sidebar windows.
The following methods are available as part of 'context. PlatformServices`:
- `context. PlatformServices.Device()': Returns the device type (Browser, Android, iOS).
- `context. PlatformServices.FingerpintAvailible()': Returns ‘True’ if a fingerprint scanner is available.
- `context. PlatformServices.EnableFingerpint()': Enables the fingerprint scanner.
- `context. PlatformServices.DisableFingerpint()': Disables the fingerprint scanner.
- `context. PlatformServices.FingerpintEnabled()': Checks if the fingerprint scanner is enabled.
- `context. PlatformServices.SetAppLock()': Sets lock on the application.
- `context. PlatformServices.ChangeAppPinLock()': Sets PIN to lock on the application.
- `context. PlatformServices.AppLockEnabled()': Checks if lock is set on the application.
- `context. PlatformServices.ScanBarcode(BarcodeType)': Scans the barcode by the set type.
- `context. PlatformServices.OpenUrl("url")': Opens a new bookmark in the browser at the provided URL.
- `context. PlatformServices.OpenFromBase64Url(url)': Opens a new bookmark in the browser at the provided Base64 URL.
- `context. PlatformServices.OpenApp(appUrl)': Opens the application at the provided URL.
- `context. PlatformServices.CanOpenApp(params string[] appUrls)': Checks if the app can be opened on the device.
- `context. PlatformServices.CanUsePayment()': Checks payment possibilities.
- `context. PlatformServices.StartPayment()': Starts the payment process.
- `context. PlatformServices.SMSRetriever()': Allows you to receive SMS.
- `context. PlatformServices.ShowDialog(string message, string title)': Shows a simple dialog with an OK button.
- `context. PlatformServices.ShowDialog(ComponentID, title, hSize, vSize, style)': Shows a simple dialog on component ID with specified dimensions, title, and CSS styles.
- `context. PlatformServices.Confirm(string message, string title = "")': Shows a dialog with Yes/No buttons.
- `context. PlatformServices.GeolocationPosition()': Returns the current geolocation.
An example of using 'context. PlatformServices.GeolocationPosition`:
An example of using 'context. PlatformServices.Confirm`:
The following group of functions is used to determine on which device and at what resolution the current user has the interface open:
- `context. PlatformServices.IsDesktop()': Returns ‘True’ if the interface is open on the desktop.
- `context. PlatformServices.IsMobile()': Returns ‘True’ if the interface is open on a mobile device.
- `context. PlatformServices.IsExtraSmall()': Returns ‘True’ if the interface is open on a screen smaller than 576px.
- `context. PlatformServices.IsSmall()': Returns ‘True’ if the interface is open on a screen larger than 576px.
- `context. PlatformServices.IsMedium()': Returns ‘True’ if the interface is open on a screen larger than 768px.
- `context. PlatformServices.IsLarge()': Returns ‘True’ if the interface is open on a screen larger than 992px.
- `context. PlatformServices.IsExtraLarge()': Returns ‘True’ if the interface is open on a screen larger than 1200px.
context.PlatformServices.Sidebar.Builder
¶
`context. PlatformServices.Sidebar.Builder' is used to create windows that open at one of the specified positions relative to the main window (form) of the application - at the top, bottom, on the right, or left.
Before a sidebar can be called, it must be built as follows:
Functions for opening sidebar in different positions:
Python | |
---|---|
context.PlatformServices.DialogBuilder
¶
The functions of 'context. PlatformServices.DialogBuilder' are used to create modal windows that open on top of the current application window (form).
Example of a set of functions that create and display a modal window on top of the current window. It is important to change the ID of the component and the window (page) to be used:
context.SessionManager
¶
`context. SessionManager' can be used to retrieve data about a user's token, as well as to make the user leave the session.
Available methods:
- `context. SessionManager.GetAccessToken()': Gets the current token.
- `context. SessionManager.UpdateToken(token)': Updates the token to a new one.
context.SessionManager.LogOut()
: Terminates the current session for the user (user logout).
context.Runtime
¶
`context. Runtime' can be used to call JavaScript functions. Void can be used to call functions without a return value. Async can be used for asynchronous call.
Available methods:
- `context. Runtime.Invoke()': Calls the function.
- `context. Runtime.InvokeVoid()': Calls the function with no return value.
- `context. Runtime.InvokeAsync()': Calls the function asynchronously.
context.Runtime.InvokeVoidAsync()
: Asynchronously calls a function with no return value.
context.UserInfo
¶
`context. UserInfo' can be used to work with a user account.
Available methods:
- `context. UserInfo.Identity()': Retrieves information about the current user.
context.UserInfo.Identities()
: Retrieves a list of all user identifiers.
context.ConfirmationServices
¶
`context. ConfirmationServices' can be used to open simple dialogs.
Available methods:
- `context. ConfirmationServices.Confirm(message, header, icon)': A simple confirmation dialog with a specified message, header, and icon.
- `context. ConfirmationServices.ConfirmAsync(message, header, icon)': A simple modeless confirmation dialog with a specified message, header, and icon.
context.ConfirmationServices.StateTheReason(header)
: Simple dialog with a header and OK button.
smth.Busy(boolean)
, smth.Error(boolean, string)
, smth.GetDynamicFilterValue(string)
¶
The Busy(boolean)
method puts a UIElement into loading status, shows or hides the preloader. The Error(boolean, string)
method puts a UIElement into error status, shows an error message. The GetDynamicFilterValue(string)
method calculates the value of a Dynamic filter. If there are two filters on one field, the first one in the list will be calculated
Examples:
SIP in Component Script¶
Checking SIP Availability: You can manage SIP availability by accessing the Enabled property.
Making and Ending a Call: You can make a call and end a call using the following methods:
Adding CRUD methods for data-flow script scenarios¶
Adding CRUD methods for entity manipulation: This code utilizes the catalogs
library, which provides methods for working with entity sets. First, an entity_set instance is created with the corresponding identifier. Then, operations for creating, updating, and deleting records are formed using the create()
, update()
, and delete()
methods respectively. Corresponding properties are set for each operation, and corresponding commands are executed.