how to display something that comes from a variabl...
# 🤝help
i
Hey, how can I display something that I have in the code to the user? I tried creating a workflow variable named "result" and then in the code I'd do workflow.result = "something" when I console.log(workflow.result) I get "something", but when I try to display it through a card, I get nothing
a
Hey @important-dawn-82568, encapsulate the var name in {{ double curly brackets }} and it should work 😃
i
do you mean like this?
this is what I get
a
hi @important-dawn-82568 can you try one or the other? for example, either @resultat or {{workflow.resultat}}
i
In my case i am not capturing the value from the user, I am filling it in the code through the "execute" action
After an API call, i fill the result variable with the result of the API call
a
ekip just to rule out simple fixes did you try to remove the @ in {{@resultat}} and replacing it with {{workflow.resultat}}. If you're able to, can you share a screenshot of what your variables look like?
i
at the same time, I am doing a console.log(workflow.resultat) in the execute code, and it gives this :
a
The double curly brackets or @ notation only work when the var is a string. If
workflow.resultat
is an object, try
{{JSON.stringify(workflow.resultat)}}
i
I defined it as a string tho
here is the whole code of how I am setting this variable :
Copy code
js
fetch(url)
  .then((response) => {
    if (response.ok) {
      return response.json()
    } else {
      throw new Error('API request failed when querying persons')
    }
  })
  .then((data) => {
    // Handle the API response data
    const matchingPersons = data.matchingPersons
    // Do something with the matchingPersons data
    const count = matchingPersons.length
    workflow.resultat = `Nous avons trouvé ${count} résultats`

    if (count > 0) {
      const firstThreePersons = matchingPersons.slice(0, 3)
      workflow.resultat += ' Les premiers résultats sont :'

      firstThreePersons.forEach((person, index) => {
        workflow.resultat += `\n${index + 1}. Nom : ${person.nom}, Téléphone : ${person.tel}`
      })
    }

    console.log(workflow.resultat) // this logs the right expected result
    console.log(matchingPersons)
    // Continue with further logic or actions based on the response
  })
  .catch((error) => {
    console.error('Error calling API:', error)
    // Handle the error
  })
a
This setup worked well on my end. Are you calling the variable in the same way?
i
Yes ! exactly the same way
is it because of the fact that I fill it inside the api call
?
a
it might be a race condition, where the flow is moving on before the API call finishes
I'm not too familiar with JS, but you could maybe put an
await
before the fetch? Or somewhere else in the code 😅
71 Views