Now I was able to build a html table with the issues information.
But i was not able to change the date format with moment.
What I want to achieve is that the updated column shows e.g. “Yesterday” or “1 day ago”
I’ve already tried:
I added
moment = require(‘moment’);
to the test and to the script section in the template - but nothing worked.
At the moment I think I have to copy the response and modify the json - but to be honest I’m not sure if it is the right way.
How have you built the HTML table? (Built where?) Can you show your code?
Can you also please clarify what you are trying to do.
Are you trying to assert on whether the updated date is yesterday or 1 day ago, or do you want to change the response to show the text yesterday or x days ago instead of the actual date. (Is it always 1 day or can this be different).
If you want to change the field in the response, then you should be able to do this as long as you parse it with var instead of constant so it can be changed.
var response = pm.response.json()
I would recommend that you parse it and change the data first before you use it elsewhere. (Although I’m not really sure what you are trying to do, hence the clarification).
If it really is days ago, then the following can work this out.
var updated = "2022-11-30T15:16:58.000+0100"
console.log(updated);
var noOfDays = moment(updated, "YYYYMMDD").fromNow();
console.log(noOfDays);
I would probably keep the template as simple as possible and make changes to the response outside of this before its used in the visualizer.
When you set the template, instead of using pm.response.json(), you would use whatever variable you have already parsed (and updated).
It looks like you should be able to do it inline though.
Not sure you have that line correct as you haven’t told it to use moment. I suspect it’s just using the built in JavaScript manipulation of dates instead of the moment library.
A key concept is that you need to ID your elements in the table. They need to be unique so you can target them ByID in the script. The handlebars have a key for each row that you can use in conjunction with the header for each column to create unique ID’s.