Using pm.environment.get inside the visualizer template variable

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”;

Hey @RowDogSA

Welcome to the community! :rocket:

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 :grin:

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;

Do you need the script in there?

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

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

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