# Using pm.environment.get inside the visualizer template variable

**URL:** <https://community.postman.com/t/using-pm-environment-get-inside-the-visualizer-template-variable/15179>\
**Category:** Help Hub\
**Tags:** variables, visualizer\
**Created:** [August 20, 2020, 7:24am UTC](https://community.postman.com/t/using-pm-environment-get-inside-the-visualizer-template-variable/15179 "2020-08-20T07:24:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![RowDogSA](https://avatars.discourse-cdn.com/v4/letter/r/d26b3c/32.png) [@RowDogSA](https://community.postman.com/u/RowDogSA)\
**Post date:** [August 20, 2020, 7:24am UTC](https://community.postman.com/t/using-pm-environment-get-inside-the-visualizer-template-variable/15179/1 "2020-08-20T07:24:23Z")

</div>

I can’t seem to access an environement or global variable from inside the template variable. For example, I have created environment variable “x” with value “5”. If I add the following inside the template var within script tags, it doesn’t work:

pm.environment.get(“x”);  
x = “something else”;

---

<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:** [August 20, 2020, 7:40am UTC](https://community.postman.com/t/using-pm-environment-get-inside-the-visualizer-template-variable/15179/2 "2020-08-20T07:40:13Z")

</div>

Hey @RowDogSA

Welcome to the community! 🚀

Could you provide the full test script that you have, please? It’s easier to see what’s going on with the full context in front of us 😁

---

<div class="post-metadata">

**Author:** ![RowDogSA](https://avatars.discourse-cdn.com/v4/letter/r/d26b3c/32.png) [@RowDogSA](https://community.postman.com/u/RowDogSA)\
**Post date:** [August 20, 2020, 10:08am UTC](https://community.postman.com/t/using-pm-environment-get-inside-the-visualizer-template-variable/15179/5 "2020-08-20T10:08:49Z")

</div>

This is an example of my Test Script and it works perfectly:

```
var template = `
<style type="text/css">
.sectionHeader {margin-left:100px;margin-top:5px;font-size:18px;color:#ffffff;float: left;border-radius: 15px;background-color: #0077bd;padding:8 16 8 16;clear:right;}
.tftable {font-size:14px;color:#333333;width:100%;border-width: 1px;border-color: #0077bd;border-collapse: collapse;}
.tftable th {font-size:18px;color:#ffffff;background-color:#0077bd;border-width: 1px;padding: 8px;border-style: solid;border-color: #0077bd;text-align:left;}
.tftable tr {background-color:#ffffff;}
.tftable td {font-size:14px;border-width: 1px;padding: 8px;border-style: solid;border-color: #0077bd;}
.tftable tr:hover {background-color:#e0ffff;}
</style>

<table class="tftable" border="1">
        <tr>
            <th>Response 1</th>
            <th>Response 2</th>
            <th>Response 3</th>
        </tr>
        
        {{#each response}}
            <tr>
                <td>{{response_1}}</td>
                <td>{{response_2}}</td>
                <td>{{response_3}}</td>
            </tr>
        {{/each}}
    </table>
`;

pm.visualizer.set(template, {
    response: pm.response.json()
});

```

If I add the following code above the table, it works fine:

```
<div class="sectionHeader"></div>
<script> 
	var y = document.getElementsByClassName('sectionHeader');
	y[0].innerHTML="HEADING";
</script>

```

I then create Global variables in my environment globals pane:  
Variable “x” with initial and current value “HEADING”  
Variable “y” with initial and current value “document.getElementsByClassName(‘sectionHeader’);”

If I change the content of my script tag to this it does not work:  
pm.globals.get(“x”);  
pm.globals.get(“y”);  
y[0].innerHTML=x;

---

<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:** [August 20, 2020, 10:33am UTC](https://community.postman.com/t/using-pm-environment-get-inside-the-visualizer-template-variable/15179/6 "2020-08-20T10:33:50Z")

</div>

Do you need the script in there?

Could you not just directly add it rather than getting the element:

```auto
<div class="sectionHeader">${pm.globals.get("x")}</div>

```

---

<div class="post-metadata">

**Author:** ![RowDogSA](https://avatars.discourse-cdn.com/v4/letter/r/d26b3c/32.png) [@RowDogSA](https://community.postman.com/u/RowDogSA)\
**Post date:** [August 20, 2020, 11:46am UTC](https://community.postman.com/t/using-pm-environment-get-inside-the-visualizer-template-variable/15179/7 "2020-08-20T11:46:06Z")

</div>

That does it! Thank you. I didn’t realise I could do that.
