# How to get nested variable set as global?

**URL:** <https://community.postman.com/t/how-to-get-nested-variable-set-as-global/13498>\
**Category:** Help Hub\
**Tags:** tests\
**Created:** [June 18, 2020, 1:40pm UTC](https://community.postman.com/t/how-to-get-nested-variable-set-as-global/13498 "2020-06-18T13:40:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![PG\_Alex](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/pg_alex/32/4761_2.png) [@PG\_Alex](https://community.postman.com/u/PG_Alex)\
**Post date:** [June 18, 2020, 1:40pm UTC](https://community.postman.com/t/how-to-get-nested-variable-set-as-global/13498/1 "2020-06-18T13:40:55Z")

</div>

Hi There,

I’m trying to get the “id” value from the response I get into a global variable.

Now I’m told that the proper way to do this is to use this as a testscript:

```
let response = pm.response.json();
pm.globals.set("attachementid", response.id);

```

But the response is nested in the manner below and there may be multiple attachments (it’s a request that gives attachments and my next move is to use another request using the id (set properly as a global variable) to delete the attachments).

```
[
    {
        "id": "7296c158-a313-4b7b-b9bb-fc4bcc757dcf",
        "fileName": "Alex.txt",
        "downloadUrl": "/tas/api/incidents/id/5857f8e5-49ea-407a-b452-bfbcf737242d/attachments/7296c158-a313-4b7b-b9bb-fc4bcc757dcf/download",
        "size": 0,
        "description": null,
        "invisibleForCaller": false,
        "entryDate": "2020-06-18T13:16:13.000+0000",
        "operator": {
            "id": "f5ebc9f7-9dff-5af3-bb48-776ebb2e3734",
            "name": "Buzing, Alex"
        },
        "person": null
    },
    {
        "id": "f092d46c-8d17-4628-92de-7e268021f309",
        "fileName": "test.txt",
        "downloadUrl": "/tas/api/incidents/id/5857f8e5-49ea-407a-b452-bfbcf737242d/attachments/f092d46c-8d17-4628-92de-7e268021f309/download",
        "size": 0,
        "description": null,
        "invisibleForCaller": false,
        "entryDate": "2020-06-18T12:50:35.000+0000",
        "operator": {
            "id": "f5ebc9f7-9dff-5af3-bb48-776ebb2e3734",
            "name": "Buzing, Alex"
        },
        "person": null
    }
]

```

Maybe you could point me in the right direction?

Regards, Alex

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [June 18, 2020, 2:12pm UTC](https://community.postman.com/t/how-to-get-nested-variable-set-as-global/13498/2 "2020-06-18T14:12:35Z")

</div>

Hey @PG_Alex

Welcome to the community! 🚀

The response is an `array` which has a couple of `objects` within it. You would need to reference the `object` that you would like the `id` value from to set that as the variable.

For example, this would get the `id` from the first `object`:

```
pm.globals.set("attachementid", response[0].id); 

```

It’s zero-indexed so `0` would be the first one, `1` would be the second one…and so on.

Hope this helps! 😃

---

<div class="post-metadata">

**Author:** ![PG\_Alex](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/pg_alex/32/4761_2.png) [@PG\_Alex](https://community.postman.com/u/PG_Alex)\
**Post date:** [June 18, 2020, 3:35pm UTC](https://community.postman.com/t/how-to-get-nested-variable-set-as-global/13498/3 "2020-06-18T15:35:32Z")

</div>

Hi Danny,

It sure did, it was exactly waht I was looking for!

Thanks for your elaborate reply.

Cheers, Alex
