Share feedback, ideas and get community help

Updated 3 months ago

Script - I Can´t get typebot variable value as JSON Object

Hello guys I need your help.

I execute a API and save the response (a JSON) in a variable named "resultados".
In the next script block I have a javascript to perform this json get some information saved in a variable "resultString ". how typebot save a variable as json object? As I read all variables are save as string. I tried with JSON.parse but continue with erro. How typebot indentify a json object. this code if I run in a JSFRiddle run successfully

example code: is a function with a typebot variable as parameter

function formatarAgendamentos(jsonData) {
var resultado = "";

// Função para formatar a data
function formatDate(date) {
var d = new Date(date);
var formattedDate = ("0" + d.getDate()).slice(-2) + "/" + ("0" + (d.getMonth() + 1)).slice(-2);
var formattedHour = ("0" + d.getHours()).slice(-2) + ":" + ("0" + d.getMinutes()).slice(-2);
return formattedDate + " " + formattedHour;
}
var numAgendamento = 1;
// Percorrendo os médicos e seus agendamentos
jsonData.data.h.forEach(function(medico) {
resultado += medico.name + "\n";

medico.datas.forEach(function(agendamento) {
resultado += numAgendamento + ") " + formatDate(agendamento.dtmarcacaoIni) + "\n";
numAgendamento++;
});
resultado += "\n";
});

return resultado;
}

// Exemplo de utilização

var jsonData = {{resultados}};

var resultadoFormatado = formatarAgendamentos(jsonData);
console.log(resultadoFormatado);
setVariable('z',resultadoFormatado)
Attachments
image.png
image.png
m
B
5 comments
more information
the documentation explain: see picture:
it is impossivel use {{=JSON.stringify({{MYvariable}})=}} in the HTTP request / save in variables / set variable. in this field only variable names accept
This is too dense
Please pinpoint the issue
Simplify the reproduction
At least a video recording or something 🙂
Add a reply
Sign up and join the conversation on Discord