Workflow - check if data exists in startTrigger

Does anyone know how to check if a data parameter exists with the workflows branch? If you have a startTrgger with data like this:

{
     "key":"123",
     "element2":"123345"
}

I know how to check the above in a branch to check to see if key = "123" By doing a simple branch and then startTrigger.data.key != "123" or something like that.

However, what about if something is sent and that person leaves out the key element like this?

{
     "element2":"123345"
}

How do I create a branch and then check to see if the "key" data element even exists before I do further checking? Thanks!

Hi @macphreak,

There are a few ways to do this, the safest way is probably startTrigger.data.hasOwnProperty('key') which returns a boolean you can branch off of.

2 Likes

Awesome. Thanks! What is the best way to check for mysql data return? Just a quick branch like "getMySQL.data[0]"? Or is there a more accurate rate to ensure data is coming back?

That depends a bit more on what you want to check for. Any records? A specific value? It'll depend on your data structure, but getMySQL.data?.length > 0 would allow you to check if any rows were returned.

2 Likes