How to get date using moment in the v2 builder?

async (event, steps, params) => {
  const moment = require("moment")
  this.date = moment().subtract(1, 'days').format('YYYY-MM-DD')
}

This is the step I made originally, which for ages gave me issues, which turned out to be because I was using guides and help posts on this forum and the documentation which were all for the v1 builder, and I was on v2. I’ve since set up my whole workflow on the v1 builder and it works fine.

However I assume v2 will be the way forward, and I don’t want my setup to end up breaking, so I want to get it working on the v2 builder.

In my next step of the workflow I reference the ‘date’ variable by the line:

url: 'www.test.com/date=${step.constant.date}',

I only include this, because I assume that there is both a new way to declare/transfer a variable between steps, and a new way to call them?
I’ve checked the documentation (the ‘migration’ page) and I tried the setups it mentions regarding making data_stores and things, but it seems so much more convoluted than the old v1 method that I’m sure I’m doing something incorrectly. Thought it was best to just ask!

Thankyou

Hi @nirurin

The concept for exporting data between steps is the same, just accessing it is slightly different.

This short video explains how to export and use data in Node.js code steps:

Long story short, instead of:

this.date = moment().subtract(1, 'days').format('YYYY-MM-DD')

You can exportusing the built in$.export` helper:

$.export('date', moment().subtract(1, 'days').format('YYYY-MM-DD'))

Or you can simply return the value:

return moment().subtract(1, 'days').format('YYYY-MM-DD')