$arrayContains
Checks whether a value exists in an array. Returns true, false, or null (when the array itself is null). Used when the array may contain numbers, where the in operator cannot always be applied directly.
Definition
$arrayContains := function($array, $v){
$exists($array)
? $array = null
? null
: $sum($map($array, function($data){ $data = $v ? 1 : 0 })) > 0 ? true : false
: null
};
Parameters
| Parameter | Type | Description |
|---|---|---|
$array |
array or null | The array to search in |
$v |
any | The value to search for |
Return value
| Situation | Returns |
|---|---|
| Value found in array | true |
| Value not found | false |
Array is null |
null |
| Array does not exist | null |
How it works
The function maps over every element in the array, returning 1 when the element equals $v and 0 otherwise. Summing those scores gives the total number of matches. If the sum is greater than 0, the value was found.
This avoids the limitation that the in operator requires a known array structure and does not handle null arrays gracefully.
Typical use case: checking material IDs
The primary use in BBILS rules is checking whether any material ID in values.layers.materialId is -1 (the Revit sentinel value for "no material assigned"):
$[type = "FamilySymbol" and values.category.label = "OST_StructuralFoundation"].{
"id": id,
"name": name,
"AllLayersMaterialised": $not($arrayContains(values.layers.materialId[], -1))
}
values.layers.materialId[] flattens the material IDs from all layers into a single array. $arrayContains(..., -1) returns true if any layer has no material. $not(...) inverts this so the output field is true when all layers are materialised.
When to use in instead
Use the in operator when:
- The array is a variable you defined (e.g. $symbolIds)
- The array contains strings or numbers from filter output
- You do not need to handle the null case
Use $arrayContains when:
- The array may be null or absent
- The array comes from a nested field on the element (e.g. values.layers.materialId)
Used in rules
rule-64c51310— Alle Structural Foundations layers zijn gematerialiseerdrule-faa50de4— Similar materialisation check