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:

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

<table class="tftable" border="1">
            <th>Response 1</th>
            <th>Response 2</th>
            <th>Response 3</th>
        {{#each response}}

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

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

<div class="sectionHeader"></div>
	var y = document.getElementsByClassName('sectionHeader');

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:

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.