Scripts
Overview
Maytas allows you to run scripts written in the open source scripting language Iron Python to add validation rules and default values for fields. While some scripts are provided by Tribal for adding standard validation rules, custom scripts can also be created to add bespoke rules and default values. Please contact Maytas Support for more information on custom scripts.
Please note that Maytas Support do not offer assistance with Iron Python scripting.
How to Run a Script
Maytas Iron Python scripts are generally provided as a text file. The text must be copied and run in Maytas as follows:
- Go to Tools | Browse Scripts.
- Select the system area to which the script applies (for custom scripts, please contact Maytas Support if you are unsure).
- There are four options for new scripts. Choose the one which applies to the script to be run:
- New Defaults – For scripts setting default values.
- New Validation – For scripts adding validation rules.
- New Process Validation – For scripts adding validation rules to a process.
- New Process Defaults – For scripts setting default values in a process.
- Enter a name for the script.
- Open the script text file in Notepad or a similar program and copy the contents.
- In Maytas 5, right-click the script area to the right and select Paste.
- Click Test if you want to validate the script. When ready, click Compile to run the script. This may take several minutes. When finished, the progress wheel will disappear and Ready will be displayed in the bottom-left corner of Maytas 5.
- Tick the Published checkbox on the left.
- Click Apply.
-
Restart Maytas 5 for the script to take effect.
Example Script - National Insurance Number Validation
The following tutorial demonstrates how a script can be used in a process for adding a learner to check that a learner with the same NI number does not already exist in the system:
-
Using the instructions for running a script in section 2, copy and run the following script (the area to select in step 2 is Trainee and the script type in step 3 is New Process Validation):
# get required types from System import * from System.Collections.Generic import Dictionary #perform check trainee = record traineeType = trainee.GetType() parameters = Dictionary[string, object]() parameters.Add('NINUMBERPARAM', trainee.Data.NINUMBER) countExisting = trainee.Persistence.CountWhere(traineeType, 'NINUMBER = @NINUMBERPARAM', parameters) if (countExisting > 0): results.AddFail('NINUMBER', 'Cannot continue - a trainee already exists with this NI number.')
-
Next, the process for adding a learner must be set to use the script for validation.
We strongly recommend creating a new process to test this functionality before editing the AddTrainee process.
- Select Tools | Process Browser.
-
To add this functionality as standard, select Trainee and double-click AddTrainee. However, as above, we strongly recommend testing this on a new process first to ensure there are no issues. To do this, double-click New Process.
If you do choose to edit the existing AddTrainee process, please skip to step 8.
- Enter a Description for the process.
- Select the Maytas tab and drag AddTraineeActivity to the design area.
- Select the activity and set ControlName to a control which has the NI Number field on it.
- Ensure that the Requires validation property is set to True.
- Set Validation script to the script created above.
- Click Apply to save the changes.
When run, this process will check the NI number you enter against the existing learners in the system. If the same NI number is found, this will produce a warning.