ScriptEvalCheck is a validation operator used in the Executable Action Language (EAL). It parses a string as OCL and verifies its syntax and type-compatibility against a specific model context without actually executing the logic or changing data.
Syntax
self.ScriptEvalCheck(IsQuery: Boolean, ReturnType: Type, Expression: String): String
IsQuery: Set tofalsefor standard actions ortruefor read-only evaluations.ReturnType: The expected model type (e.g.,Decimal,String,Integer) that the expression must return.Expression: The String attribute or literal containing the OCL code.
1. Implementation Logic
In your Action Editor, you implement ScriptEvalCheck as the condition in a let statement. This allows you to store the "check result" as a variable before deciding whether to proceed with the actual evaluation.
Action OCL Syntax:
Object Constraint Language
-- 'validationInfo' will hold the result of the check
let validationInfo = self.ScriptEvalCheck(false, Decimal, self.DynamicFormula) in
(
-- If the script is valid, 'validationInfo' is exactly 'ok'
if validationInfo = 'ok' then
-- SAFE TO EXECUTE
self.FormulaResult := self.ScriptEval(false, Decimal, self.DynamicFormula).asstring
else
-- UNSAFE: Store the error message so the user can see what's wrong
self.FormulaResult := validationInfo
endif
)
2. How it Works
When you call ScriptEvalCheck, MDriven performs three background tasks:
- Syntax Scan: It checks if the string in
self.DynamicFormulais valid OCL (e.g., no missing brackets or misspelled operators). - Type Verification: It ensures the script returns the type you requested (in our case,
Decimal). - Context Check: It confirms that all properties referenced (like
self.Total) exist on theOrderclass.
3. Visualizing Failure vs. Success
Implementing this operator is what created the "Work Visualization" we saw in your screenshots:
- Failure Implementation: When the formula was
'self.Total * 0.10',ScriptEvalCheckidentified a type mismatch between Decimal and Double. It returned a long error string, which you successfully displayed in theFormulaResultbox. - Success Implementation: When you corrected the formula to
'self.Total * 0.10.ToDecimal',ScriptEvalCheckfound no issues and returned the string 'ok'. This allowed theifstatement to trigger the actualScriptEval.
