0

I'm using an html template within the Tests tab to output my json data, however, some of the data is in timestamp form. Is there a way to do the calculation to a more standard date/time format from within the var template ? I've read several ways to convert the timestamp, even one that I tried that I've commented out at the top but none work within the template variable. I've tried a few things but they cause the call to fail. Is it even possible to do within that template? Or how would you do it outside the template and then pull it back into the html? Because of the each loop I'm just not sure how to do this.

    /*
let moment = require('moment'),
    jsonData = pm.response.json()
    date_created = jsonData.GetServerTimeResponse.date_created,
    first_seen = jsonData.GetServerTimeResponse.first_seen,
    last_seen = jsonData.GetServerTimeResponse.last_seen
*/
var template = `
    <style type="text/css">
        .tftable {font-size:14px;color:#333333;width:100%;border-width: 1px;border-color: #87ceeb;border-collapse: collapse;}
        .tftable th {font-size:18px;background-color:#87ceeb;border-width: 1px;padding: 8px;border-style: solid;border-color: #87ceeb;text-align:left;}
        .tftable tr {background-color:#ffffff;}
        .tftable td {font-size:14px;border-width: 1px;padding: 8px;border-style: solid;border-color: #87ceeb;}
        .tftable tr:hover {background-color:#e0ffff;}
    </style>
    
            Dom: {{response.result.dom}}</br>
            Rep: {{response.result.rep}}</br>
            Reg: {{response.result.reg}}</br>
            Date Created: {{response.result.date_created}}</br>
            First Seen: {{response.result.first_seen}}</br>
            Last Seen: {{response.result.last_seen}}</br>
    <table class="tftable" border="1">
        <tr>
            <th>Name</th>
            <th>Rep</th>
            <th>First Seen</th>
            <th>Last Seen</th>
        </tr>
        <tr>

        </tr>
        {{#each response.result.ns}}
            <tr id=row_{{@key}} onClick="handleClick(this.id)">
                <td id={{@key}}>{{host}}</td>
                <td>{{rep}}</td>
                <td>{{first_seen}}</td>
                <td>{{last_seen}}</td>
            </tr>
        {{/each}}
               {{#each response.result.send}}
            <tr id=row_{{@key}} onClick="handleClick(this.id)">
                <td id={{@key}}>{{id}}</td>
                <td></td>
                <td></td>
                <td>{{last_seen}}</td>
            </tr>
        {{/each}}
    </table>
`;

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

0 Answers0