Execute code not affecting workflow variables
# 🤝help
t
I have this code snippet when I get an error from the API call I want to set error_msg variable to a certain text When I try to show as text in the chat it's set as null .catch((error) => { if (error.response && error.response.data.title === 'Member Exists') { workflow.error_msg = "Error" console.error(workflow.error_msg) } else { console.error('Error:', error.response ? error.response.data : error.message) } })
c
HI youssef, not 100% the following suggestion will work but its better than nothing ha
.catch((error) => { if (error.response && error.response.data.title === 'Member Exists') { workflow.error = "Error"; } else { workflow.error = error.response ? error.response.data : error.message; } })
in your case the console.error will not display as the execute code node card cant directly print logs to the console, instead we use workflow.variables to access the result outside the code node. Then we can print those result to the user using the "@workflow.error"
t
Hello @cold-jewelry-54343 , actually I just use the console log just to debug and it works no problem. The problem is as you can see I have workflow.error_message="Error" which should set the variable. On the next node when I print that variable it shows it as null
c
make sure to have the correct spacings and syntax
t
so you would know. The problem I was facing was because the flow ends before the api call gets any error so no time for it to be stored in the variable. I added a bunch of steps before the end as a buffer and it worked fine.
2 Views