> For the complete documentation index, see [llms.txt](https://docs.work-relay.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.work-relay.com/automations/global-actions-and-action-groups/using-actions/using-variables-in-global-actions-and-action-groups.md).

# Using variables in global Actions and Action Groups

In spite of $Variables context object is not presented in objects lists on Global actions setup screen one can use it for complicated logic settings.

Below is example of using variables within global action group. Form in the example is tied up to Account object.

{% stepper %}
{% step %}

## Create a global action group and global action

* First, create Global Action Group. [How to create an Action Group](/automations/global-actions-and-action-groups/basics/working-with-action-groups.md#how-to-create-an-action-group).
* Then create Global Action within the action group. [Working with actions](/automations/global-actions-and-action-groups/basics/working-with-actions.md#how-to-create-an-action).
* Choose **Context object** (1), e.g., "Account"
* Choose "**Define Variable**" Action Type (2)
* Choose "**Query**" variable type in Define Variable Settings section (3)
* Choose **object** to be queried, e.g., "Contact" (4)
* Click "**Add Field**" button, select Email field and set variable name (5)
* Add **condition** to query only contacts that have email value provided (6)
* Switch to **Advanced settings** mode, choose ‘Account’ context object and choose ‘Account ID’ context object item (7)
* Using Account ID value add **condition** to query only records that are tied up to the current account (8)
* Set query **Limit** (9)

Save Global Action. Add second Global Action to the action group.
{% endstep %}

{% step %}
![](/files/70af804e8e07d48027104ccd45c4c0cebefa5643)

## Configure the email alert action

* Choose "Account" **context object type** (10)
* Select "Email Alert" **action type** (11)
* Switch to "**Advanced**" email alert settings mode (12)
* Fill in "**To**" field with variable #1 value getting its value via `{$Variables}` context object: `{$Variables.contact_emails}` (13)
* Provide email **Subject** and **text**.

Save global action.

![](/files/e3e57375ec056cd785a2e90fc62273c8b9723840)
{% endstep %}

{% step %}

## Add the action group to a form

Open the form you want to trigger Action Group at. Add a [Custom Button](/forms/form-components/options/custom-button.md) to the form.&#x20;

* Tie the button up to the Global Action Group (set Action Group as form action and add it as handler to the custom button "onClick" event)
* Add `{$Account.Id}` as a source

Save the form.
{% endstep %}

{% step %}

## Run the form

* Run the form (pass account that has contacts child records to the form as source record)
* Click custom button - as a result of the global action execution related contacts will receive emails
  {% endstep %}
  {% endstepper %}
