# SharinPix Form Formula: Fields and Attributes

### Overview <a href="#overview" id="overview"></a>

{% hint style="info" %}
The **SharinPix Form Formula Field** allows you to dynamically reference and manipulate data. Using formulas, you can combine static values with live data coming from form inputs and other sources to create flexible, data-driven form templates.

This article covers the following:

* [Accessing Form Fields](#overview)
* [Accessing Attributes of Form Fields](#accessing-attributes-of-form-fields)
  {% endhint %}

{% hint style="success" %}
**Tips:**&#x20;

[Follow this documentation](https://docs.sharinpix.com/forms/form-elements/sharinpix-form-formula-functions-and-operators) to learn more about the Functions and Operators available in a SharinPix Form Formula Field
{% endhint %}

### Getting Started <a href="#getting-started" id="getting-started"></a>

Formulas can reference data from the following sources:

1. **Current Form Fields:** Values entered by the end-user (e.g., <mark style="color:red;">`elementAPIName`</mark>).
2. **URL Parameters:** Data passed when launching the form via the <mark style="color:red;">`form.params.`</mark> prefix (e.g., <mark style="color:red;">`form.params.approval_threshold`</mark>).

### Accessing Form Fields <a href="#configure-visibility-conditions-1" id="configure-visibility-conditions-1"></a>

Any question with an API name can be used in a formula field. An API name can be added to a question using the *API Name field* on the form builder, as shown below.

<figure><img src="https://2647402409-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrRD1Xcn9HtKcyfQ9Ghyk%2Fuploads%2FarK37VC4ZGFC9EVRPKba%2Ftest.png?alt=media&#x26;token=54e92066-3e60-47e0-a461-2a92797d1adf" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2647402409-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrRD1Xcn9HtKcyfQ9Ghyk%2Fuploads%2FxcE0wuuhlx7ly1qZ4VPC%2Ftest.png?alt=media&#x26;token=d8152d8a-200b-46be-9572-28037535db10" alt=""><figcaption></figcaption></figure>

The SerialNumber field can then be used in formula fields as shown above

{% hint style="danger" %}
A section or page cannot contain fields with the same API name.
{% endhint %}

#### Accessing nested fields <a href="#accessing-nested-fields" id="accessing-nested-fields"></a>

To access a nested field, i.e a field found inside a section, make sure to add an API name to the Section element as well. In the picture below the API name "Bedroom" is added to a Section element.

<figure><img src="https://2647402409-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrRD1Xcn9HtKcyfQ9Ghyk%2Fuploads%2FNHP6QreBfRyIl8EGFatN%2Ftest.png?alt=media&#x26;token=9cfcbe10-fa55-422a-9560-9867268b8039" alt=""><figcaption></figcaption></figure>

The "Bedroom" Section element contains a Radio question with the "ACWorking" API name as shown below.

<figure><img src="https://2647402409-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrRD1Xcn9HtKcyfQ9Ghyk%2Fuploads%2FFnJpMP8t1HSMCEfurM5k%2Ftest.png?alt=media&#x26;token=dfaaabb4-1408-4205-a335-0774bf5ef0bb" alt=""><figcaption></figcaption></figure>

To reference the "ACWorking" Radio question in a formula field found **outside** the "Bedroom" Section, it should be *prefixed* with the Section's API name as shown in the example below.

<figure><img src="https://2647402409-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrRD1Xcn9HtKcyfQ9Ghyk%2Fuploads%2FZ05yL8ttQgPdyqlRaHCa%2Ftest.png?alt=media&#x26;token=ad36eee9-b7dd-4009-93be-47f9a9d33227" alt=""><figcaption></figcaption></figure>

{% hint style="success" %}
**Tips:**&#x20;

A field can be referenced without any prefix if it is being used in the same level (i.e, the section where it is found)
{% endhint %}

#### Accessing parent fields

The <mark style="color:red;">`parent`</mark> attribute is available for any question found in a section.

<figure><img src="https://2647402409-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrRD1Xcn9HtKcyfQ9Ghyk%2Fuploads%2FaGNzmbYt0Bxtxb3R3dYL%2FSharinPix%20Form%20Formula%20Fields%20and%20Attributes%20(4).png?alt=media&#x26;token=14dd54aa-d6e4-4ddb-8697-77f0c1b5fbae" alt=""><figcaption></figcaption></figure>

By using the <mark style="color:red;">`parent`</mark> attribute, we can access the attributes of the section as shown below.&#x20;

<figure><img src="https://2647402409-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrRD1Xcn9HtKcyfQ9Ghyk%2Fuploads%2FP86guKpYUvRDGWtEtd5I%2FSharinPix%20Form%20Formula%20Fields%20and%20Attributes%20(5).png?alt=media&#x26;token=de419615-5db7-4b51-ad2b-b697bb43a30b" alt=""><figcaption></figcaption></figure>

{% hint style="success" %}
**Tips:**

You can use <mark style="color:red;">`.parent`</mark> to move up the elements tree and reference questions in other sections. For example:

<mark style="color:red;">`parent.parent.SiblingSection.ACWorking`</mark>
{% endhint %}

if you need to reference a **root-level (main page)** question inside a formula field for a question **nested** in a section, you can reference it by using the [**form**](#global-form-attributes) global field.

In the example below, the form includes a radio question with the API name <mark style="color:red;">`VisitType`</mark> on the main page, and a capture question inside the **Bedroom** section.

<figure><img src="https://2647402409-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrRD1Xcn9HtKcyfQ9Ghyk%2Fuploads%2FTUKEQwAOwuIFb7ncVdX4%2FSharinPix%20Form%20Formula%20Fields%20and%20Attributes%20(1).png?alt=media&#x26;token=2896d1ef-1e69-4ad4-879d-33f9c7bd2aa8" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2647402409-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrRD1Xcn9HtKcyfQ9Ghyk%2Fuploads%2FhQ2AGvB3ssI19GllNumM%2FSharinPix%20Form%20Formula%20Fields%20and%20Attributes%20(2).png?alt=media&#x26;token=14eeb1b0-bf37-4413-b611-a8101c65c093" alt=""><figcaption></figcaption></figure>

To reference <mark style="color:red;">`VisitType`</mark> from a formula on a question in the **Bedroom** section, use <mark style="color:red;">`form.VisitType`</mark>, as shown below.

<figure><img src="https://2647402409-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrRD1Xcn9HtKcyfQ9Ghyk%2Fuploads%2Fef43aOOJ83dhCVHpDWQy%2FSharinPix%20Form%20Formula%20Fields%20and%20Attributes%20(3).png?alt=media&#x26;token=20a7c219-d918-4136-ba3f-ab84cadbd6c7" alt=""><figcaption></figcaption></figure>

### Accessing Attributes of Form Fields <a href="#accessing-attributes-of-form-fields" id="accessing-attributes-of-form-fields"></a>

A field can contain several attributes based on its type and they can be accessed by adding a "." following a field API name.

#### Generic Questions attributes <a href="#generic-questions-attributes" id="generic-questions-attributes"></a>

These attributes are available on almost all questions.

<figure><img src="https://2647402409-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrRD1Xcn9HtKcyfQ9Ghyk%2Fuploads%2FrZp2FdcglQC00b0gq0mD%2FSharinPix%20Form%20Formula%20Fields%20and%20Attributes%20(7).png?alt=media&#x26;token=0ff52f92-ded9-4055-aaae-80763f4e43f6" alt=""><figcaption></figcaption></figure>

| Attribute    | Purpose                                                                                                                                                                                                      |
| ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| value        | Returns the current value of the field                                                                                                                                                                       |
| displayValue | Returns the current value of the field as displayed on the UI                                                                                                                                                |
| label        | Returns the label of the question                                                                                                                                                                            |
| mediaCount   | Returns the number of media associated with the question                                                                                                                                                     |
| note         | Returns the current note added to the question if any                                                                                                                                                        |
| reference    | Return the previous value of the question in the context of a [follow-up form](https://docs.sharinpix.com/forms/advanced-form-configuration/form-features-initial-follow-up-form-responses-comparative-form) |
| visible      | Returns whether the question is currently visible or not (This is available to use only if the question has a visibility formula configured)                                                                 |

**displayValue attribute**

This attribute returns the current value of the field as shown on the UI.

For example, if a question has a label configured for a particular value, then that label will be returned in the formula as shown below.

<figure><img src="https://2647402409-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrRD1Xcn9HtKcyfQ9Ghyk%2Fuploads%2F2MDe0XJGbnERBngmfwzO%2FDOC%20SF%20-%201920%20x%201080%20(46).png?alt=media&#x26;token=e9b6a208-38a3-4dd1-9908-b43dbeb7daf4" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2647402409-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrRD1Xcn9HtKcyfQ9Ghyk%2Fuploads%2FRqryT5ZvJ8jzRTLgsFXy%2FDOC%20SF%20-%201920%20x%201080%20(47).png?alt=media&#x26;token=dd76dc29-10fd-4769-be27-85f125af5c95" alt=""><figcaption></figcaption></figure>

For date questions it returns the date value as a formatted string, using the date format configured on the question.

<figure><img src="https://2647402409-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrRD1Xcn9HtKcyfQ9Ghyk%2Fuploads%2FOGlpfhkQ0HzhhGmZgcFh%2FDOC%20SF%20-%201920%20x%201080%20(48).png?alt=media&#x26;token=489c3b20-c5d4-442e-9fec-f7866c86a5d5" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2647402409-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrRD1Xcn9HtKcyfQ9Ghyk%2Fuploads%2FdViz9xPgBsSmGuzdPF7e%2FDOC%20SF%20-%201920%20x%201080%20(45).png?alt=media&#x26;token=408c2da4-1432-45d4-972f-e131959663a5" alt=""><figcaption></figcaption></figure>

#### Section Attributes <a href="#section-attributes" id="section-attributes"></a>

These attributes are only available to sections.

<figure><img src="https://2647402409-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrRD1Xcn9HtKcyfQ9Ghyk%2Fuploads%2FVpmXeNODKnipcgjGyBV0%2Ftest.png?alt=media&#x26;token=f36bcc44-bc5c-4454-ae43-a3d7cce55138" alt=""><figcaption></figcaption></figure>

| Attribute              | Purpose                                                                     |
| ---------------------- | --------------------------------------------------------------------------- |
| \_questionsCount       | Returns the number of visible questions that are inside the section         |
| \_questionsFilledCount | Returns the number of visible questions that have filled inside the section |
| index                  | Returns the index of the section if it a repeated section                   |

The API names of the questions inside the Section are also attributes of the Section.

If a Section is a Repeated Section, it will also have the <mark style="color:red;">`index`</mark> attribute, which returns its position in the Repeated element as shown below.

<figure><img src="https://2647402409-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrRD1Xcn9HtKcyfQ9Ghyk%2Fuploads%2FX9JJLY4p1PMH23u0xdsO%2Ftest.png?alt=media&#x26;token=d78b9812-5c8e-4506-82c1-c14d00ef1a28" alt=""><figcaption></figcaption></figure>

### Repeated Sections attributes

These attributes are only available to the Repeated Sections element.

<figure><img src="https://2647402409-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrRD1Xcn9HtKcyfQ9Ghyk%2Fuploads%2FwT7e86Hc5ML3cjezSc8d%2Ftest.png?alt=media&#x26;token=697497cd-42f5-4e01-80d0-4812beac882f" alt=""><figcaption></figcaption></figure>

| Attribute | Purpose                                          |
| --------- | ------------------------------------------------ |
| size      | Returns the number of sections added by the user |

The nested fields of the repeated sections can also be referenced. Follow [this documentation](https://docs.sharinpix.com/forms/form-sections-and-repeated-sections/sharinpix-form-formula-referencing-repeated-section-fields) to learn more.

#### Global form attributes <a href="#global-form-attributes" id="global-form-attributes"></a>

There are several global attributes that can be accessed by using the <mark style="color:red;">`form`</mark> keyword

<figure><img src="https://2647402409-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrRD1Xcn9HtKcyfQ9Ghyk%2Fuploads%2FQuYpIXtWX4cXLTdTdKOk%2Ftest.png?alt=media&#x26;token=17a25164-39be-4bd7-bf21-e5f2e2a97fcc" alt=""><figcaption></figcaption></figure>

| Attribute | Purpose                                                                                                                                                                                                                                                |
| --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| compare   | Returns <mark style="color:red;">`true`</mark> when the form being filled is a follow-up form.                                                                                                                                                         |
| params    | Allows accessing the url params found in the url that was used to load the form. Follow [this documentation](https://docs.sharinpix.com/forms/advanced-form-configuration/sharinpix-forms-context-parameters) to learn more about this attribute.      |
| response  | Returns details of the SharinPix Form Response record. This can be used to show additional details on the [SharinPix Form PDF](https://docs.sharinpix.com/forms/form-pdf-configuration/sharinpix-forms-pdf-configuration).                             |
| template  | Returns details of the SharinPix Form Template record.                                                                                                                                                                                                 |
| view      | Returns <mark style="color:$danger;">`"print"`</mark> in the context of pdf. This is useful for hiding or show specific fields on the [SharinPix Form PDF](https://docs.sharinpix.com/forms/form-pdf-configuration/sharinpix-forms-pdf-configuration). |

**response attribute**

This attribute of the <mark style="color:red;">`form`</mark> global field contains nested attributes about a SharinPix Form Response record created by the form.

<figure><img src="https://2647402409-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrRD1Xcn9HtKcyfQ9Ghyk%2Fuploads%2FZjNyROKwAb0ieSdNNz96%2Ftest.png?alt=media&#x26;token=5d15baaf-ab44-4bbc-9539-36114e214774" alt=""><figcaption></figcaption></figure>

| Attribute | Purpose                                                |
| --------- | ------------------------------------------------------ |
| sfid      | The Salesforce Record ID linked to the form response   |
| sfname    | The Salesforce Record Name linked to the form response |

**template attribute**

This attribute of the <mark style="color:red;">`form`</mark> global field contains nested attributes about the SharinPix Form Template record.

<figure><img src="https://2647402409-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrRD1Xcn9HtKcyfQ9Ghyk%2Fuploads%2FJLx9a4lMOsAMtjUXV9ii%2Ftest.png?alt=media&#x26;token=c606e21a-332c-4bb5-99e0-883c5527f169" alt=""><figcaption></figcaption></figure>

| Attribute | Purpose                |
| --------- | ---------------------- |
| sfid      | The Form Template ID   |
| sfname    | The Form Template Name |

**Root-level fields**

The questions found on the main page can also be referenced directly by using the <mark style="color:red;">`form`</mark> field as shown below.

<figure><img src="https://2647402409-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrRD1Xcn9HtKcyfQ9Ghyk%2Fuploads%2FJTIa2KdfdHsGRkPKMggI%2FSharinPix%20Form%20Formula%20Fields%20and%20Attributes%20(6).png?alt=media&#x26;token=1cebfe42-38f8-4579-9052-aff7d6152cdb" alt=""><figcaption></figcaption></figure>

{% hint style="success" %}
**Tips:**

This can be used to reference a root-level question from a nested formula field.
{% endhint %}
