# Link

## How It Works&#x20;

A **Link** node allows to override the values of the running node variables. A **Link** node runs another node, passing the variables set by a user to it. After the run, dynamic variables of the node are set as dynamic variables of the **Link** node parent group. Thus the result of the run can be seen from any of the neighboring **Link** node.

#### You can refer to:

* a [RequestStep](https://docs.testmace.com/master/node-types/request-step) node;
* a [Folder](https://docs.testmace.com/master/node-types/folder) node.

#### You can NOT refer to:

* Another **Link** node (including self);
* Any child of a **Link** node (since it'll cause an endless loop).

{% hint style="info" %}
A Link node allows to override the variables values of the parent node.
{% endhint %}

{% hint style="warning" %}
If you delete the link a Link node refers to, the Link node wouldn't run until you provide a proper link.‌
{% endhint %}

## Parent Node

Create a parent node you need to refer to and create all necessary [static variables](https://docs.testmace.com/master/variables/user-variables/static-variables), for example `postID`. You can leave value fields empty.

![Creating variables of the parent node](https://1914040845-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LYfhIaTTw23Sf3L5jfe%2F-Lh4Cqr7blB3FIHuJKO_%2F-Lh4ImcwyK7QPl4D0WmO%2Flink-parent-var.jpg?alt=media\&token=e7b7f466-1fb2-4924-ad13-21d465e236ae)

## Link Node

Create a **Link** node and specify its parent, and you'll see all the variables you created for the parent earlier. You can use any variables or a static value as an overriden value.

![Creating a Link node and specifying its parent](https://1914040845-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LYfhIaTTw23Sf3L5jfe%2F-Lh4SwfExBEdfIX5P1HC%2F-Lh4VLCDdb58k9EvDvPd%2Flink-node-ex2.gif?alt=media\&token=98246c48-371b-43f2-9e7c-cbcb3abcce80)

## Scenario Example

Let's see an example of running a [RequestStep](https://docs.testmace.com/master/node-types/request-step) node as a **Link** node to delete a record.

### Creating a parent node

1. Create a new [RequestStep](https://docs.testmace.com/master/node-types/request-step) node named deletePost.
2. Request type - DELETE.
3. Use the URL:[ https://testmace-stage.herokuapp.com/posts/${id}](https://testmace-stage.herokuapp.com/posts/$%7Bid%7D)
4. Create for this node a [static ](https://docs.testmace.com/master/variables/user-variables/static-variables)`id` variable without specifying its value.

![](https://1914040845-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LYfhIaTTw23Sf3L5jfe%2F-LhFNVvYEIb0YxX8C1eJ%2F-LhFNaKST0F0_1ymsVjY%2Flin-sc-1.gif?alt=media\&token=7e93b682-f174-4ea0-b928-3714bd0fd476)

### **Creating a scenario**

* Create a [Folder](https://docs.testmace.com/master/node-types/folder) node named **scenario**
* Add a [RequestStep](https://docs.testmace.com/master/node-types/request-step) node named **createPost** to the scenario:
  * Request type: POST;
  * URL: [https://testmace-stage.herokuapp.com/posts/](https://testmace-stage.herokuapp.com/posts/$%7Bid%7D)
  * Body: JSON request `{"title":"will delete with link node"}`
  * Run the request and the `id` of the created record to the [dynamic variable ](https://docs.testmace.com/master/variables/user-variables/dynamic-variables)`postid` of the **Scenario** node.

![](https://1914040845-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LYfhIaTTw23Sf3L5jfe%2F-LhFNVvYEIb0YxX8C1eJ%2F-LhFQ274uAmdp39J7uz7%2Flin-sc-2.gif?alt=media\&token=6b7597c8-32dc-4598-8e42-94ac76ad3cbe)

* Create a **Link** node named **deleteLink**.
  * Specify the **project/deletePost** node as a parent.
  * &#x20;Set the`${$dynamicVar.postId}` as an overridden value for the `id` variable of the parent **deletePost** node.
* Create a [RequestStep](https://docs.testmace.com/master/node-types/request-step) node **checkIfExists** to check if the record was deleted:
  * Request type: GET;
  * URL: [https://testmace-stage.herokuapp.com/posts/${$dynamicVar.postId}](https://testmace-stage.herokuapp.com/posts/$%7B$dynamicVar.postId%7D)
  * 404 is an expected server response.

![](https://1914040845-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LYfhIaTTw23Sf3L5jfe%2F-LhFNVvYEIb0YxX8C1eJ%2F-LhFRaKVohkgWjndBb3E%2Flin-sc-3.gif?alt=media\&token=d61d5fe1-334b-429c-b7d0-3aa78766f533)

## Import the Project [by URL](https://docs.testmace.com/master/other-features/import/shared)

{% file src="<https://1914040845-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LYfhIaTTw23Sf3L5jfe%2F-LglOdFY9U2EtljTDSqT%2F-LglQkEld_hqNoia9IpW%2Flink-node-demo.txt?alt=media&token=40485ec2-228c-4ef8-b8ab-0a9d4ea2dc46>" %}

### File Representation

A **Link** node is a folder with the node name, containing the index.yml file with the following format:

```javascript
{
  "type": "object",
  "properties": {
    "type": {
      "description": "Type of Link node",
      "const": "Link",
      "type": "string"
    },
    "linkedNode": {
      "$ref": "#/definitions/NodeReference",
      "description": "Link to node"
    },
    "children": {
      "description": "List of children names",
      "type": "array",
      "items": {
        "type": "string"
      },
      "default": []
    },
    "variables": {
      "$ref": "#/definitions/NodeVariables",
      "description": "Node variables dictionary"
    },
    "name": {
      "description": "Node name",
      "type": "string"
    }
  },
  "required": [
    "children",
    "linkedNode",
    "name",
    "type",
    "variables"
  ],
  "definitions": {
    "NodeReference": {
      "type": "object",
      "properties": {
        "refNodePath": {
          "description": "Absolute path to node",
          "type": "string"
        },
        "type": {
          "description": "Marker of reference entity",
          "const": "reference",
          "type": "string",
          "default": "reference"
        }
      },
      "required": [
        "refNodePath",
        "type"
      ]
    },
    "NodeVariables": {
      "type": "object",
      "additionalProperties": {
        "type": "string"
      }
    }
  },
  "$schema": "http://json-schema.org/draft-07/schema#"
}
```
