Scripting in Activity object
The Activity object can have a Script that executes “Before” (Script before) the inserted object and a Script that executes “After” (Script after).
A script is used for:
- Executing built in System functions for sending E-mail/SMS, manipulating text files or invoking other objects.
- Executing SQL statements and react on result.
- Conditionally execute other Activity objects using DM_ActExecute()
- Check for various conditions and SKIP the current invocation and reschedule using DM_ActLogSkip()system function
- Perform various checks and add information to the object log thereby enabling conditional signaling of Errors and Warnings which in term automatically can be picked up by the Application Monitor where notification messages are generated¨.
The script can contain:
- System functions like DM_ActExecute(), DM_ActLogMessage(), DM_Email() ..
- Expressions using Date, Time, Logical, Numeric, String algorithms.
- SQL statements using parameters to form dynamic WHERE clauses, dynamic SQL statement construction and for expression arguments.
- SQL SELECT statements can use the special keyword IntoParameter: SELECT col1,col2 IntoParameter|tag=The keyword IntoParameter;document=WordDocumentsDesign Manager.doc [<p1>], [<p2>] FROM …
- The special “handle” argument to dynamically access the temporary data collection.
- Multiple SQL statements and expressions separated by ; (semicolon)
SQL statements
After each statement is executed the result can be tested using the following system parameters.
[<SQLNRows>] Returns the number of rows affected. Returns –1 if an error occurs.
[<SQLErrorText>] Returns the error message reported by the database server when an error occurs.
The keyword IntoParameter enables a SELECT statement to retrieve data and assign it directly to parameters.
SELECT cdp_f1, cdp_f2 IntoParameter [<my parm1>],[<my parm2>] FROM form_mytable ;
The above statement selects data from the fields cdp_f1, cdp_f2 and assigns it to the parameters [<my parm1>] and [<my parm2>]
Using this technique any set of data can be retrieved from the internal database in any script as well as from any external datasource.
Expressions - and how to influence the execution of the Activity
The Activity object can react on a return value from an expression. Following is a list of system functions that can be used to execute other Activity objects or to add messages to the log and optionally influence the execution.
Special activity object functions are:
- DM_ActExecute|tag=Function: DM_ActExecute;document=WordDocumentsDialog Manager Expression functions.doc(<name/SystemId>) Executes another activity.
- DM_ActLogMessage|tag=Function: DM_ActLogMesssage;document=WordDocumentsDialog Manager Expression functions.doc(<Message text>) Adds a message to the object log.
- DM_ActLogWarning|tag=Function: DM_ActLogWarning;document=WordDocumentsDialog Manager Expression functions.doc(<Message text>) Adds a warning to the object log.
- DM_ActLogError|tag=Function: DM_ActLogError;document=WordDocumentsDialog Manager Expression functions.doc(<Message text>) Adds an error to the object log.
- DM_ActLogSkip|tag=Function: DM_ActLogSkip;document=WordDocumentsDialog Manager Expression functions.doc(<Message text>) Adds a message to the object log and terminates the object execution.
- DM_ActLogFinish|tag=Function: DM_ActLogFinish;document=WordDocumentsDialog Manager Expression functions.doc(<Message text>) Adds a message to the object log and finishes the object execution including Script after.
An expression can add a user defined message to the log or perform an action such as executing another Activity object or signaling an Error/Warning condition.
The expression must return a string value. The following is the syntax for adding information to the log and optionally at the same time influence the execution of the object.
Return values:
- Ok:<Log message text> Add the text after : as a Message to the log and continue normal execution
- Error:<Log message text> Add the text after : as an Error message to the log and signals an Error
- Warning Signals a Warning
- Warning: <Log message text> Add the text after :as a Warning message to the log and signals a Warning.
- Skip Skips further execution. If executed from Batch Manager any defined rescheduling is done.
- Skip:<Log message text> Add the text after : as a Message to the log and skips further execution. If executed from Batch Manager any defined rescheduling is done.
Example:
SELECT cdp_f1, cdp_f2 IntoParameter [<my parm1>] ,[<my parm2>]FROM form_mytable ;
SELECT cdp_myfield FROM form_mytable WHERE myotherfield = [<My Query Parameter>]; If ([<SQLNRows>] > 0 , DM_ActExecute(’My act1’) , DM_ActExecute(’My another act’) ) ;
UPDATE form_mytable SET cdp_myfield = ’xyz’ myotherfield = [<My Query Parameter>];
DM_ActLogMessage(’Number of rows updated:’ + String([<SQLNRows>]) );
If (DayName(Today()) = ’Monday’ , DM_ActLogSkip(’Not on mondays..’) ,’Ok’);
If ([<My Parameter>] = ’yes’ , ’ok’, ’Warning:Wrong answer!’);
Case( [<My Parameter>] WHEN ’yes’ THEN ’Ok:The answer was yes.’ WHEN ’no’ THEN ’Warning:The answer was no.’ ELSE ’Error:No valid answer!’ ) ;’
Availability DM 2009 SP1 Build 10008
|