Script functions, attributes and objects - validation scripts for variants and variation points
In addition to the standard Modeler automation interface functions, objects and attributes, there are special functions, objects and attributes you can use in the validation scripts for Variants and Variation Points. For general information about scripts, including information about the Modeler, Projects, ActiveProject and Dictionary objects that are available in most script functions, see
Script functions, attributes and objects - overview.
To write scripts you require a good working knowledge of the VBScript language, the Modeler Meta Model and the Modeler Automation Interface.
If you run a script that has errors, those errors can cause Modeler to crash and corrupt Modeler model data.
Note that when a variability item is referenced as a model object reference in the validation script for a Variant or Variation Point, it is the runtime Decision Set object that is referenced NOT the Modeler object. If you want to use the Modeler object, you must retrieve it through its id, for example, at runtime.
These functions are case sensitive and cannot be used in any other scripts.
• EvaluateConstraint function - All script must be within the EvaluateConstraint function.
When EvaluateConstraint returns False for a Variant or Variation Point, the Variant or Variation Point is marked as inconsistent in the Decision Set Editor and Variant Selector.
This function can use the following attributes:
◦ Excluded attribute - returns whether the Status of a Variant or Variation Point is set to Excluded in the context of the Decision Set that is being edited in the Decision Set Editor or Variant Selector. Example code:
Function EvaluateConstraint If Variant2.Excluded AND Variant3.Excluded Then EvaluateConstraint = False Script.Result = "Variant2 and Variant3 are both excluded" Else EvaluateConstraint = True End If End Function
◦ Included attribute - returns whether the Status of a Variant or Variation Point is set to Included in the context of the Decision Set that is being edited in the Decision Set Editor or Variant Selector. Example code:
Function EvaluateConstraint If Variant2.Included AND Variant3.Included Then EvaluateConstraint = False Script.Result = "Variant2 and Variant3 are both included" Else EvaluateConstraint = True End If End Function
◦ Inconsistent attribute - returns whether the Status of a Variant or Variation Point is set to Inconsistent in the context of the Decision Set that is being edited in the Decision Set Editor or Variant Selector. Example code:
Function EvaluateConstraint If Variant2.Inconsistent AND Variant3.Inconsistent Then EvaluateConstraint = False Script.Result = "Variant2 and Variant3 are both inconsistent" Else EvaluateConstraint = True End If End Function
◦ ParameterValue attribute - returns the parameter value of a Variant or Requires Dependency in the context of the Decision Set that is being edited in the Decision Set Editor or Variant Selector. Example code:
Function EvaluateConstraint If StandardSeat.Included Then If StandardSeat.ParameterValue mod 7 = 0 Then EvaluateConstraint = True Else Script.Result = "Standard seats must be in rows of 7" EvaluateConstraint = False End If Else EvaluateConstraint = True End If End Function
◦ Script.Result script attribute - When a Variant or Variation Point is marked as inconsistent, specifies text to display as the Reason for that inconsistency in the Decision Set Editor or Variant Selector. Example code:
Function EvaluateConstraint If StandardSeat.Included Then If StandardSeat.ParameterValue mod 7 = 0 Then EvaluateConstraint = True Else Script.Result = "Standard seats must be in rows of 7" EvaluateConstraint = False End If Else EvaluateConstraint = True End If End Function
◦ Undecided attribute - returns whether the Status of a Variant or Variation Point is set to Undecided in the context of the Decision Set that is being edited in the Decision Set Editor or Variant Selector. Example code:
Function EvaluateConstraint If Variant2.Undecided AND Variant3.Undecided Then EvaluateConstraint = False Script.Result = "Variant2 and Variant3 are both undecided" Else EvaluateConstraint = True End If End Function