Pengower Script Introduction
Within the Pengower Development platform (Application Builder) it is necessary to encode specific business rules to ensure that applications reflect and support real business processes. Pengower Script is a simple scripting language developed to work with the Pengower Platform to deliver the required business logic. The syntax for the script has been kept deliberately simple so that the language can be learned and mastered without a significant background in software development or IT.
Scripting is used when basic Action definitions don’t provide sufficient flexibility both in terms of functionality and in terms of visual output. Scripts are written as part of an Action definition, i.e. when the Action is called by the end user the associated script is executed. The Pengower scripting engine works in an interpreted mode – i.e. the script re-read and re-processed each time it is accessed.
Line 1 // create a new person
Line 2 Set person = Do New Object Params Type = "Person"
Line 3 Set person["First Name"] = "John"
Line 4 Output = person
Line 5 Report = "A person has been created"
Line 6 Return_Ok
Line 1 of the script is a comment line included to help other developers understand the operation of the script.
Line 2 creates a new instance of a ‘Person’ type object. ‘Person’ must be the name of a type within the application meta-structure. A detailed examination of the ‘Do’ syntax can be found later.
Line 3 sets the ‘First Name’ for the newly created Person to ‘John’. ‘First Name’ must be an Element of the Type ‘Person’ within the application meta-structure.
Line 4 assigns the new person to the output from the script, i.e. the person object will form part of the return to the user.
Line 5 provides some feedback to the user in the form of a string that will be presented in the Message Bar section of the display.
Line 6 ends the script and terminates execution with an ‘OK’ code.
A detailed explanation of all aspects of this simple script can be found in the following sections.
Each statement in ActionScript can exist on a single line and is terminated by a carriage return (i.e. new line or return). The range of allowable statements is fairly limited and they are all summarised in Script Statements Explained
Script Statements Explanation
Each statement in ActionScript can exist on a single line and is terminated by a carriage return (i.e. new line or return). The range of allowable statements is fairly limited and they are all summarised below;
// … comment statement used to add developer support to the code
// a simple comment
Set <var_name> = <expression> Creates and populates a variable with a value
|Set x = 7 + 3|
|Set person = Do New Object Params Type = "Person"|
|Set people = Get "Person"|
|Set person["First Name"] = "John"|
If <expression> / Else / EndIf
Used in combination to allow for the processing of conditionals and executing blocks of statements based on the analysis of conditional statements
|If ( x > 9 )|
|Set y = 4|
|Set y = 5|
For < var_name> = var To var / Next
Used in combination to support the basic concept of looping, i.e. executing a block of statements a set number of times
|For i = 1 To 5||Set x = x + i</tr>|
Do <command> Params <parameters>
used in conjunction with script action definitions to perform more complex operations such as adding attributes to an item or sending emails
|Do Send Email Params From=from, To=to, Subject="Test Email", Body="Nothing"|
used to terminate the execution of the script with the return code ‘OK’
used to terminate the execution of the script with the return code ‘Error’
used to pass information back to the user in the form of a string. The contents of the string will be rendered into the ‘Message Bar’ in the output display
|Report = " – the script execution completed without error"|
Output = <expression>
used to pass items, strings, arrays etc. out of the script and back to the user. The contents of Output will generally be rendered in the work region of the display. Thus, if an item (e.g. a person) is allocated to Output then that item will be returned to the user for editing.
|Output = person|
Print = <expression>
used to create a print window containing the string representation of the ‘<expression>’. The string passed to the Print parameter will be rendered in the print window as HTML. The use of HTML provides the developer with the opportunity to format the printable output as desired.
|Print = "<table><tr><td>" + person["First Name"] + "</td></tr></table>"|
Add <var_name> To <arr_name>
used to add a variable to an array type variable
|Add x To array|
This completes the list of available statements. There is however one other key construct that is used in conjunction with the ‘Set’ statement that warrants a mention at this stage – the ‘Get’ construct.
‘Get’ is used in conjunction with the ‘Set’ statement to access items in the database. Examples of the syntax for the ‘Get’ statement are;
|Set people = Get "Person"|
|Set johns = Get "Person" Where First Name = "John"|
|Set sql = "Surname =’Smith’"|
|Set smiths = Get "Person" Where sql|
Note; the use of ‘Get’ will always return an array type variable. Arrays are explained in the next section dealing with the concept of variables in ActionScript.
Each of the statement syntaxes outlined here is described in more detail in the following sections.