> For the complete documentation index, see [llms.txt](https://codifi-fdm.gitbook.io/codifi-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://codifi-fdm.gitbook.io/codifi-docs/reports/report-tag-conventions/functions-operations-comparisons.md).

# Functions, Operations, Comparisons

You can include certain functions/operations in certain tags to change the default results. Please note that some operations can only be used within report tags that pertain to collections.

#### Checkboxes

<table data-full-width="true"><thead><tr><th width="200">Operator</th><th>Description</th><th>Example</th></tr></thead><tbody><tr><td>checkbox(condition)</td><td>Returns a checkbox that is either checked or unchecked depending on if the conditions are met</td><td>{{checkbox(field(Color).contains(Blue))}}<br><br><br></td></tr><tr><td>checkboxes(field label)</td><td>You can also automagically print a set of checkboxes for all values from a selection field</td><td>{{checkboxes(field(Color))}</td></tr></tbody></table>

#### **Conditional "If/Else"**

<table data-full-width="true"><thead><tr><th width="200">Operator</th><th>Description</th><th>Example</th></tr></thead><tbody><tr><td>if(condition)</td><td>You can specific content (including other report tags) to conditional print or be hidden based on the results returned<br><br>NOTE: these <em>must</em> include opening and closing elements</td><td><p>{{if(terms)}}<br>Report content and/or other tags</p><p>{{endIf}}<br><br>They can also have "else". If the conditions of the first section aren't meant, then the system will follow the "else".<br><br>{{if(terms)}}<br><em>Content</em><br>{{else}}<br><em>Other Content</em><br>{{endIf}}<br><br>You can also nest multiple levels of conditions.<br><br>{{if(terms)}}<br><em>Content</em><br>{{else}}<br>{{if(other terms)}}<br><em>Other Content</em><br>{{else}}<br>{{if(different terms)}}<br><em>Different Content</em><br>{{else}}<br><em>Unique Content</em><br>{{endIf}}<br>{{endIf}}<br>{{endIf}}</p></td></tr></tbody></table>

#### **Comparison Operators**

| Operator               | Description                                                                | Example                                                                     |
| ---------------------- | -------------------------------------------------------------------------- | --------------------------------------------------------------------------- |
| **`equals(value)`**    | Boolean. Checks if the current value *exactly matches* the given value.    | `{{Status.equals(Complete)}}`                                               |
| **`notEquals(value)`** | Boolean. Checks if the current value *does not match* the given value.     | `{{Priority.notEquals(Low)}}`                                               |
| **`contains(value)`**  | Boolean. For **arrays** or **text**, checks if the value includes a match. | `{{field(Site Characteristics).contains(Artifact Scatter)}}`                |
| **`excludes(value)`**  | Boolean. Checks if a string/array *does not contain* the specified value.  | `{{Notes.excludes(draft)}}`                                                 |
| **stringArrayHasAny**  | Boolean. Returns true if the values in a field meet *any* condition        | stringArrayHasAny(OneOption,Another option,Location Map,And SOMETHING ELSE) |
| **stringArrayHasAll**  | Boolean. Returns true if the values in a field meet *all* conditions       | stringArrayHasAll(Location Map,NONE)                                        |

#### **Numeric Operators**

| Operator                      | Description                                                                 | Example                          |
| ----------------------------- | --------------------------------------------------------------------------- | -------------------------------- |
| **`isGreater(value)`**        | Boolean. True if current numeric value is *greater than* given value.       | `{{Count.isGreater(10)}}`        |
| **`isGreaterOrEqual(value)`** | Boolean. True if current value is *greater than or equal to* given value.   | `{{Score.isGreaterOrEqual(75)}}` |
| **`isLess(value)`**           | Boolean. True if current value is *less than* the given number.             | `{{DaysRemaining.isLess(7)}}`    |
| **`isLessOrEqual(value)`**    | Boolean. True if current value is *less than or equal to* the given number. | `{{Progress.isLessOrEqual(50)}}` |

#### Collection and Filtering Operators

| Operator                                                                                  | Description                                                                                       | Example                                                                                                                     |
| ----------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- |
| **`filter(condition)`**                                                                   | Filters a list or collection by a condition. Often used with `sections`, `children`, or `medias`. | `{{sections.filter(Title.equals(Architectural Features))}}`                                                                 |
| **`first(collection)`**                                                                   | Returns the *first* item from a collection or filtered result.                                    | `{{first(children).name}}`                                                                                                  |
| **`count(collection)`**                                                                   | Returns the *number of items* in a collection.                                                    | `{{count(children)}}`                                                                                                       |
| **`any(condition,condition)`**                                                            | Returns `true` if there are any that match *any* condition given (they match some or all).        | `{{children.any(Status.equals(Complete))}}`                                                                                 |
| **and(condition,condition)**                                                              | Returns true if there are any that match *all* conditions given.                                  |                                                                                                                             |
| **or(condition,condition)**                                                               | Returns true if there are any that match one or another condition separately.                     |                                                                                                                             |
| **not(condition)**                                                                        | Returns true if it does *not* match the condition given                                           |                                                                                                                             |
| *NOTE: operators like any, and, or, not, etc can be used in conjunction with one another* | not(and(or(condition,condition),condition))                                                       |                                                                                                                             |
| **in(**                                                                                   | Returns what is *in* a specified collection or set of values                                      | first(field(Attachments).toStringArray.stringArrayToRcos.filter(equals(NONE)).in(Paced,NONE,Taped,Visual Estimate).toString |
| **`union(collections...)`**                                                               | Combines multiple collections into one.                                                           | `{{union(children,record.siblings)}}`                                                                                       |

#### Data Transformation/Utility Functions

<table><thead><tr><th width="228.84375">Function</th><th>Description</th><th>Example</th></tr></thead><tbody><tr><td><strong><code>toString</code></strong></td><td>Converts a value to string (useful before <code>.contains()</code>).</td><td><code>{{field(Name).toString}}</code></td></tr><tr><td><strong><code>toStringArray</code></strong></td><td>Splits comma-separated text into an array, enabling <code>.contains()</code> logic.</td><td><code>{{field(Site Characteristics).toStringArray.contains(Rock Art/Inscription)}}</code></td></tr><tr><td><strong><code>toLocalString</code> / <code>toLocalDateString</code></strong></td><td>Formats a <code>DateTime</code> object into readable string form.</td><td><code>{{field(Date Recorded).toLocalDateString}}</code></td></tr><tr><td><strong>toUTCDateString</strong></td><td>Similar to above, but doesn't localize</td><td><code>{{field(Date Recorded).toUTCDateString}}</code></td></tr><tr><td><strong><code>toOrdinal</code></strong></td><td>Converts a number into ordinal form (1 → “1st”).</td><td><code>{{field(Position).toOrdinal}}</code></td></tr><tr><td><strong>stringArrayToRcos</strong></td><td>When a value is transformed from string to array in a single object, for example a field, using the tag “toStringArray”, is can be nice to explode this array of values into an array of object, making each string value an independent object we can query, filter, count, etc</td><td>count(field(Attachments).toStringArray.stringArrayToRcos).toString</td></tr><tr><td><strong>toInt</strong></td><td>Converts a valid String to an integer. The input String should start with an integer number. If the String contains non-integer numbers, the function will stop performing the conversion.</td><td>field(Measurement).toInt</td></tr><tr><td><strong>toStringFormat(F#)</strong></td><td>Trims an numeric value to the specified number of decimal places</td><td>(latitude).toStringFormat(F6)</td></tr><tr><td><strong>toFeet</strong></td><td>When used on a number field, multiplies by 3.28084. Returns a number, may require .toString in certain cases.</td><td>{{locations.accuracy.toFeet.toString}}</td></tr><tr><td><strong>multiplyBy(x.yz)</strong></td><td>When used on a number, multiplies by the provided number. Returns a number.</td><td>{{field(Minutes).multiply(60)}}</td></tr></tbody></table>

***

## New in v3.3

A large batch of functions landed in v3.3. They follow the same chained accessor pattern as everything above: apply them to a value with a dot.

### Compass Bearings

Turn a bearing in degrees into a readable direction. Most often used on a photo's image direction so a caption reads "view to the northeast" rather than "view to 43 degrees".

| Function           | Description                                              | Example                                  |
| ------------------ | -------------------------------------------------------- | ---------------------------------------- |
| **`toCardinal`**   | Degrees to a 4-point compass label: N, E, S, W.          | `{{medias.imageDirection.toCardinal}}`   |
| **`toOctant`**     | Degrees to an 8-point label: N, NE, E, SE, S, SW, W, NW. | `{{medias.imageDirection.toOctant}}`     |
| **`toHexadecant`** | Degrees to a 16-point label: N, NNE, NE, ENE, and so on. | `{{medias.imageDirection.toHexadecant}}` |

### UTM Coordinates

Convert a location into UTM. Use `toUtm` when you want the whole reference, or the individual accessors when the template needs the parts in separate cells or paragraphs.

| Function            | Description                        | Example                       |
| ------------------- | ---------------------------------- | ----------------------------- |
| **`toUtm`**         | Full UTM conversion of a location. | `{{locations.toUtm}}`         |
| **`toUTMEasting`**  | Easting only.                      | `{{locations.toUTMEasting}}`  |
| **`toUTMNorthing`** | Northing only.                     | `{{locations.toUTMNorthing}}` |
| **`toUTMZone`**     | Zone only.                         | `{{locations.toUTMZone}}`     |

{% hint style="info" %}
**Rounding UTM values.** Easting and northing come back with decimals. Most agency forms want whole meters, so pair them with `toStringFormat(F0)`.
{% endhint %}

### Photo Metadata

| Function                | Description                                                         | Example                              |
| ----------------------- | ------------------------------------------------------------------- | ------------------------------------ |
| **`imageDirection`**    | The compass bearing a photo was taken at, in degrees.               | `{{medias.imageDirection.toString}}` |
| **`imageDirectionRef`** | Whether the stored bearing is referenced to true or magnetic north. | `{{medias.imageDirectionRef}}`       |
| **`metadata`**          | Access a photo's EXIF metadata.                                     | `{{medias.metadata}}`                |
| **`metadataString`**    | The same, rendered as a string.                                     | `{{medias.metadataString}}`          |

See [Media Metadata](/codifi-docs/reports/report-tag-conventions/report-tags-and-properties/media-metadata.md) for the full set of photo properties.

### Working with Lists

The string-array family grew. These matter for multi-select Fields, where a single Field holds several values.

| Function                  | Description                                                                        | Example                                                  |
| ------------------------- | ---------------------------------------------------------------------------------- | -------------------------------------------------------- |
| **`stringToStringArray`** | Splits a delimited string into an array.                                           | `{{field(Materials).stringToStringArray}}`               |
| **`stringArrayToString`** | Joins an array back into one string.                                               | `{{field(Materials).toStringArray.stringArrayToString}}` |
| **`stringArrayCount`**    | How many entries an array holds.                                                   | `{{field(Materials).toStringArray.stringArrayCount}}`    |
| **`fromStringArray`**     | Converts an array back to a single value.                                          | `{{field(Materials).toStringArray.fromStringArray}}`     |
| **`rcosToStringArray`**   | The inverse of `stringArrayToRcos`: collapses objects back to an array of strings. | `{{children.rcosToStringArray}}`                         |

### The "Other" Value on Select Fields

When a dropdown offers an Other option with a free-text box, the typed value needs separate handling from the picked options. These four do that.

| Function                             | Description                                              |
| ------------------------------------ | -------------------------------------------------------- |
| **`singleSelectFieldOther`**         | The free-text Other value from a single-select Field.    |
| **`singleSelectFieldContainsOther`** | True when a single-select Field has an Other value set.  |
| **`multiSelectFieldOthers`**         | The free-text Other values from a multi-select Field.    |
| **`multiSelectFieldContainsOthers`** | True when a multi-select Field has any Other values set. |

```
{{if(field(Site Type).singleSelectFieldContainsOther)}}
Other: {{field(Site Type).singleSelectFieldOther}}
{{endif}}
```

### Other Additions

| Function         | Description                                                                       | Example                      |
| ---------------- | --------------------------------------------------------------------------------- | ---------------------------- |
| **`toDecimal`**  | Converts a value to a decimal number, for arithmetic on text that holds a number. | `{{field(Depth).toDecimal}}` |
| **`fieldValue`** | The raw stored value of a Field, before display formatting.                       | `{{fieldValue(Status)}}`     |
| **`archetype`**  | The Archetype of the current Record.                                              | `{{archetype.name}}`         |
| **`self`**       | The current object, for chaining where an explicit subject is needed.             | `{{self.toString}}`          |
| **`project`**    | The Project, reachable from anywhere in a template.                               | `{{project.name}}`           |
