# Create Formula Expressions

Learn about creating formula expressions using Safety-specific functions.

## About Formula Expressions

Safety Vaults include several formula expressions that you can use when configuring certain features, including:

* <a href="/en/gr/01288/">E2B Generation Data Mapping</a>
* <a href="/en/gr/726960/">Follow-Up Questionnaires</a>
* <a href="/en/gr/679957/">QC Checklists</a>
* <a href="/en/gr/860152/">Individual Case Routing</a>
* <a href="/en/gr/832805/">Rules Based Narratives</a>
* <a href="/en/gr/01250/">Reporting Rules</a>
* <a href="/en/gr/869628/">Inbox Item Significance</a>
* <a href="/en/gr/873418/">Safety Data Expression Building Blocks</a>
* <a href="/en/gr/01461/">Custom Validation Criteria</a>


For more information about using formulas in Vault, see:

* <a href="/en/gr/42857/">Creating Formulas in Vault</a>
* <a href="/en/gr/52324/">Vault Formula Reference Guide</a>
* <a class="external-link " href="https://developer.veevavault.com/vql/#criteria-vql" target="_blank" rel="noopener">Criteria VQL<i class="fa fa-external-link" aria-hidden="true"></i></a>

## Safety Functions

The following functions are specific to Safety. You can use these functions to define expressions that return true or false:

* [`VS_ANYOF`][1]
* [`VS_CONTAINS`][2]
* [`VS_HASONE`][3]
* [`VS_HASMANY`][4]
* [`VS_LET`][5]
* [`VS_MATCHES`][6]

Certain features support additional Safety-specific functions:

* <a href="/en/gr/832805/#safety-functions">Narrative functions</a> for <a href="/en/gr/832805/">Rules Based Narratives</a>
* <a href="/en/gr/869628/#criteria">Significance functions</a> for <a href="/en/gr/869628/">Inbox Item Significance</a>

### VS_ANYOF {#vs_anyof}

`VS_ANYOF(array_expression, LAMBDA(array_element_alias, boolean_expression))`

This function returns true or false depending on whether or not the `boolean_expression` is true for any of the array elements (`array_element_alias`) in the `array_expression`.

#### Example

The following example returns true if any of the _Case Adverse Events_ related to this _Case_ have a _Days Hospitalized_ value of two (2) or more:

`VS_ANYOF(case_version__v.case_adverse_events_case_version__vr.days_hospitalized__v, LAMBDA (e,e>2))`

### VS_CONTAINS {#vs_contains}

`VS_CONTAINS(string array, string)`

This function returns true or false depending on whether or not the `string` is present inside the `string array`.

#### Example

The following example returns true: 

`VS_CONTAINS(["one", "two", "three"], "two")`

### VS_HASONE {#vs_hasone}

`VS_HASONE(objectreference)`

This function returns true if there is exactly one (1) record of the specified object for the _Case_.

#### Example

The following example returns true if the _Case Product_ has one (1) _Case Product Indication_:

`VS_HASONE(case_version__v.case_products_case_version__vr.case_product_indications__vr)`

### VS_HASMANY {#vs_hasmany}

`VS_HASMANY(objectreference)`

This function returns true if there are multiple records of the specified object for the _Case_.

#### Example

The following example returns true if the _Case Product_ has multiple _Case Product Indications_:

`VS_HASMANY(case_version__v.case_products_case_version__vr.case_product_indications__vr)`

### VS_LET {#vs_let}

`VS_LET(var, path_to_validating_records, expression)`

This function returns the result of a validation performed on object records. This function includes the following inputs:

* `var`: Specifies an alias to the records found at the resolved `path_to_validating_records`. You can use this alias in place of the path in your expression to make it easier to read.
* `path_to_validating_records`: Specifies the object path Vault validates, beginning from the top-level object (for example, `case_version__v`, `transmission__v`, `localized_case__v`) or the specified `var`, with each following node in the path separated by a period (`.`). The path navigates through the objects using the appropriate object field relationship names.
* `expression`: Specifies the expression Vault will evaluate on the validating records, returning as true or false.

#### Example

The following example validates that when the _MPID_ field of a _Case Product_ contains a value, the _MPID Version_ must also contain a value:

 `VS_LET(cp, case_version__v.case_products_case_version__vr, IF(NOT(ISBLANK(cp.mpid__v)),NOT(ISBLANK(cp.mpid_version__v)),TRUE))`

### VS_MATCHES {#vs_matches}

`VS_MATCHES(string, string)`

This function returns true or false depending on whether or not `string` matches the regular expression (regex) in `string`.

#### Example

The following example returns true: 

`VS_MATCHES("veeva", "^veeva.*$")`


[1]: #vs_anyof
[2]: #vs_contains
[3]: #vs_hasone
[4]: #vs_hasmany
[5]: #vs_let
[6]: #vs_matches
