Skip to main content
Best answer

Javascript: How can I catch 'undefined' before it errors

  • October 21, 2020
  • 4 replies
  • 1518 views

Probably a simple fix. I am expecting a value, but occassionally the data is undefined because of empty data. I would like Javascript code step to catch it instead of the zap erroring out. Any tips to use IF statement or another method to catch an undefined before it errors the code step when I use .length on it.

error when estimateid is undefined
 
current code. works fine unless the Estiamtes ID is undefined

 

Best answer by olivialookBest answer by olivialook

Would it work in your flow to use a JS try...catch here? 

View original
Did this topic help you find an answer to your question?
This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

4 replies

olivialook
Forum|alt.badge.img+1
  • New
  • 16 replies
  • Answer
  • October 21, 2020

Would it work in your flow to use a JS try...catch here? 


  • Author
  • Beginner
  • 8 replies
  • October 22, 2020
olivialook wrote:

Would it work in your flow to use a JS try...catch here? 

I will give that a try, thank you!


  • Author
  • Beginner
  • 8 replies
  • October 22, 2020

I will have to wait to see if this will work with actual data. but THANK YOU.

 


  • Author
  • Beginner
  • 8 replies
  • November 16, 2020
ITplumber wrote:
olivialook wrote:

Would it work in your flow to use a JS try...catch here? 

I will give that a try, thank you!

WORKING PERFECTLY. Thank you. Zap does not error our now, it outputs 0 if the data is undefined.