Share feedback, ideas and get community help

Updated 10 months ago

JavaScript Block

Hello Everyone!
I am looking to understand how to proceed with JavaScript Block interact with Condition Block, this is my JS script.
Basically I am converting a timestamp date to DD/MM/YYYY and checking after convertion if the date is 7 days ahead or no.

var setVariable{{diferencaDias}};

function verificarPrazo({{DATAINICIOASSINATURA}}) {
const data = new Date(timestamp);

const dia = String(data.getDate()).padStart(2, '0');
const mes = String(data.getMonth() + 1).padStart(2, '0'); // Janeiro é 0!
const ano = data.getFullYear();
const dataFormatada = dia + '/' + mes + '/' + ano;

const agora = new Date();
const diferencaTempo = agora.getTime() - data.getTime();
diferencaDias = diferencaTempo / (1000 * 3600 * 24);

if ({{diferencaDias}} > 7) {
setVariable({{FORADOPRAZO}});
} else {
setVariable({{DENTRODOPRAZO}});
}
}
B
T
6 comments
What's the issue?
I am not able to check if var diferencaDias is greather or less than 7 days. I am pretty sure I am doing something wrong, but not sure if this in the code or no.
Let me explain with more details:

The flow starts after a user want to cancel a subscription of a product, so in this print below (not the entire flow), I am just checking if a subscription is valid or no, then I will check if the subscription is 7 days ahead of start or no.
There is a typo on else DENTRO box, I already correct it to different text of IF
You need to debug the thing, try to print the variables in text bubbles before the condition blocks to see if your script worked correctly
Add a reply
Sign up and join the conversation on Discord