Coded rules
While declarative rules provide a lot of flexibility, occasionally, the configuration logic requires even more functionality. Coded rules allow the implementation of a wider variety of conditions and generate a large number of rule effects.
Coded rules use a simple business rules language for defining conditional logic and actions in a modular fashion. Rules help determine how certain components and tags should be allowed, blocked, or configured based on conditions such as tag presence, component placement, or attribute values. The language is readable, flexible, and intended to be easy for both technical and non-technical stakeholders to write, review, and maintain.
This rules language provides a straightforward way to define conditions and actions. By combining tags, placements, components, and attributes, you can tailor logic to enable or block features, require input, or set properties. The use of ANY, ALL, NOT, and the straightforward IF ... THEN ... END structure keeps rules readable and easy to maintain.
Tips
Use TAGGED to detect an active tag.
Use COMPONENT(component IN placement) to check if a component is in a specific placement.
Use HASVALUE(attribute OF placement) to check for attribute presence.
Use actions like BLOCK, ALLOW, SELECT, REQUIRESTRING, REQUIRENUMBER, or SET to enforce behavior once conditions are met.
Combine conditions with implicit AND or explicit ANY/ALL.
Negate any condition with NOT.
Use double-quotes to wrap values with spaces and special characters such as #
Rule syntax
A rule is typically structured as:
IF <condition(s)>
THEN
<action(s)>
END
Rules can be declared in sequence (one after another) or nested (an IF THEN block inside another). Each rule must end with the END keyword.
Conditions can be combined in several ways:
Single condition: IF TAGGED(spiked) THEN ...
Multiple conditions (implicitly combined using AND operator): All listed conditions must be true for the rule to apply.
IF TAGGED(spiked)
COMPONENT(LacesWhite IN ShoeLaces)
THEN
...
END
Alternatively, rules can be combined using explicit ANY OF operation: the rule applies if at least one condition is true.
IF ANY OF
TAGGED(spiked)
COMPONENT(SoleRubber IN ShoeSole)
THEN
...
END
Finally, rules can be combined using explicit ALL OF operation: the rule applies if all conditions are true.
IF ALL OF
TAGGED(spikeless)
HASVALUE(stamp-text OF ShoeToe)
THEN
...
END
Else actons
A rule may also have ELSE block which can contain actions to be performed if the rule condition fails. For example:
IF <condition(s)>
THEN
<action(s)>
ELSE
<alternate action(s)>
END
Additionally, ELSEIF can be used to perform a chain of checks, optionally ending at ELSE condition:
IF <condition(s)>
THEN
<action(s)>
ELSEIF <condition(s)>
<alternate action(s)>
ELSEIF <conditions>
<more actions(s)>
...
ELSE
<final actions(s)>
END
Negation
Any condition, single or combination operator, can be prefixed with NOT, for example:
NOT TAGGED(spiked)NOT COMPONENT(LacesWhite IN ShoeLaces)IF NOT ANY OF …
Condition functions
TAGGED(tag): Checks whether a specified tag is active (e.g., TAGGED(spiked)).TAGGED(tag IN placement): Checks whether a component with the specified tag is active in the placement(e.g., TAGGED(spiked IN sole)).COMPONENT(component IN placement): Checks whether a specific component is placed in a given placement (e.g., COMPONENT(SoleVibram IN ShoeSole)).HASVALUE(attribute OF placement): Checks whether a particular attribute on a placement is present or set (e.g., HASVALUE(stamp-text OF ShoeToe)).ISLOCALE(locale): Checks whether a specified locale is active (e.g., ISLOCALE(en-US))ISSITE(site): Checks whether a specified site is active (e.g., ISSITE(Shopify))ALWAYS: Always passes the condition check (e.g.,IF ALWAYS THEN BLOCK …)CHANGED(placement): Only runs the rule when the specified placement has changed
Keywords
The language uses several standard keywords when combining multiple statements:
IN: Indicates a location or container relationship, as in COMPONENT(LacesWhite IN ShoeLaces).OF: Indicates ownership or a property relationship, as in HASVALUE(stamp-text OF ShoeToe).TO: Used for assignment, as in SET("Approved" TO stamp-text OF ShoeSole).
Variables
Variables can be referenced anywhere an identifier is allowed using VAR(name) syntax. This enables dynamic values in conditions and effects:
LET(myTag AS ATTRIBUTE(selectedTag OF options))
IF TAGGED(VAR(myTag)) THEN
DEBUG(VAR(myTag))
END
Define and assign a variable using a LET effect:
LET(variable-name AS variable-value)
Variable value can be calculated using a formula-like syntax, please see the Expression chapter. Once defined, variables can be reassigned new values if necessary.
Access a variable using VAR expression:
VAR(variable-name)
If a variable is not yet defined, an empty value will be returned.
Case sensitivity
Language keywords, statements, and effects must be in uppercase.
Effects
Effects are applied when a rule is activated. Some effects result in the enablement or disablement of specific components, similar to declarative rules. Other rule effects allow to perform more explicit actions, such as selecting a component into a placement.
Availability effects
BLOCK(tag): Prevent or remove any component or functionality associated with the specified tag.BLOCK(tag IN placement): A variation of the BLOCK effect that applies only to components of a specific placement.BLOCKALL(placement): Blocks all components within the placement. This effect is typically followed by one or moreALLOWeffects to enable some of components in the placement.ALLOW(tag): Permit or enable components or functionality associated with the specified tag.ALLOW(tag IN placement): A variation of the ALLOW effect that applies only to components of a specific placement.
Selection effects
SELECT(component IN placement): Select or enable a particular component in the specified placement.SELECTBYTAG(tag IN placement): Select or enable a particular tagged component in the specified placement.
Update configuration
SET(value TO attribute OF placement): Assign a value to a specific attribute in the specified placement.SETCOMPONENTPRICE(value TO component IN placement): Assign a price to a specific component in the specified placement.UPDATEBLUEPRINT(value OF path): Updates the blueprint configuration value, for example a view or a group property.
Requirement and validation effects
REQUIRESTRING(attribute OF placement): Enforce that the named attribute is set to a string value.REQUIRENUMBER(attribute OF placement): Enforce that the named attribute is set to a numeric value.
Variable assignment
LET(name AS expression): Assigns the result of an expression to a variable for use in subsequent rules.
Debugging
DEBUG(expression): Outputs the value of an expression for debugging purposes.
Other effects
ACTION(name arg0 arg1 …): When an effect is triggered, a controller eventruleEventwill be triggered. An event will be triggered at most once per each state change.
Expressions
Expression functions can be used within LET and DEBUG effects.
Effect function | Example | Description |
|---|---|---|
COMPONENT | COMPONENT(placement) | Returns the component at the specified placement |
ATTRIBUTE | ATTRIBUTE(name OF placement) | Returns the attribute value |
TAGS | TAGS(placement) | Returns the tags at a placement |
FINDPLACEHOLDER | FINDPLACEHOLDER(placement) | Finds a placeholder by path |
FINDACTUAL | FINDACTUAL(placement) | Finds the actual component |
TOUPPER | TOUPPER(value) | Converts value to uppercase |
TOLOWER | TOLOWER(value) | Converts value to lowercase |
CONCAT | CONCAT(value value ...) | Concatenates multiple values |
REPLACE | REPLACE(value pattern replacement) | Replaces pattern in value |
Examples
Below are some rule examples using the specific placements (ShoeSole, ShoeToe, ShoeLaces), components (LacesWhite, LacesBlack, SoleRubber, SoleVibram, ToeLeatherBlack, ToeLeatherWhite), attribute (stamp-text), and tags (spiked, spikeless).
Single condition: checking if a tag is active
IF TAGGED(spiked) THEN
BLOCK(spikeless)
END
Explanation: If spiked is active, then we block anything tagged with spikeless.
Multiple conditions (implicit AND) and effects
IF TAGGED(spikeless)
COMPONENT(SoleRubber IN ShoeSole)
THEN
SELECT(SoleVibram IN ShoeSole)
SET("UltraActive" TO stamp-text OF ShoeSole)
END
Explanation: If spikeless is active AND SoleRubber is currently in ShoeSole,
we replace it with SoleVibram in ShoeSole,
and set the attribute stamp-text of ShoeSole to "UltraActive".
Using ANY OF (OR condition)
IF ANY OF
NOT TAGGED(spiked)
COMPONENT(LacesWhite IN ShoeLaces)
THEN
BLOCK(spiked)
END
Explanation: If either spiked is not active OR LacesWhite is in ShoeLaces, then we block spiked. In other words, as soon as one of the conditions is true, the actions (BLOCK(spiked)) are executed.
Using ALL OF (AND condition)
IF ALL OF
TAGGED(spiked)
HASVALUE(stamp-text OF ShoeToe)
THEN
REQUIRESTRING(stamp-text OF ShoeToe)
SELECT(ToeLeatherBlack IN ShoeToe)
END
Explanation: If spiked is active AND there is a stamp-text attribute set on ShoeToe,
we require that stamp-text is a string value,
and we select ToeLeatherBlack in ShoeToe.
Negation
IF NOT COMPONENT(LacesBlack IN ShoeLaces) THEN
SELECT(LacesWhite IN ShoeLaces)
END
Explanation: If LacesBlack is not present in ShoeLaces, then select LacesWhite in ShoeLaces.
Requiring number attribute
IF TAGGED(spiked) THEN
REQUIRENUMBER(stamp-text OF ShoeSole)
END
Explanation: If spiked is active, enforce that stamp-text on ShoeSole must be numeric. This could be used to store something like a size code or numeric identifier.
Nested rules
IF COMPONENT(SoleVibram IN ShoeSole) THEN
IF TAGGED(spiked) THEN
SET("Spiked Vibram" TO stamp-text OF ShoeSole)
END
IF ANY OF
TAGGED(spikeless)
NOT HASVALUE(stamp-text OF ShoeSole)
THEN
SET("Default Sole" TO stamp-text OF ShoeSole)
END
END
Explanation:
The outer condition checks if SoleVibram is placed in ShoeSole.
Then inside:
If spiked is also active, set the stamp-text of ShoeSole to "Spiked Vibram".
If either spikeless is active or stamp-text is missing, set the stamp-text to "Default Sole".