I am working on my first workflow and trying to set up a filter. In the screenshot below I have a query that retrieves 1 record. I reference it in the filter and want to stop the workflow if a record exists.
Indexes are 0 based, so if your array only has one record, it is found at index 0 and there are no records with an index > 0.
Not sure I understand the use of the filter - maybe try a branch that checks if getStoredEvents.data.length == 1 and stops, or else does something else (assuming you want it to do something else).
I want the filter to stop the workflow if a record exists. My next block is to insert a record only if it is not yet in the table. It seems whatever I try the filter doesn't work and the next block fires.
The filter is to reduce the number of records you are dealing with. What you are describing is a branch which either terminates the workflow or does something else, along the lines of this:
New Record (Start Trigger ID of 150 not in DB which goes to 50)
Existing record (Start Trigger ID 50 is found)
However, an easier approach to an UPSERT is to just use the GUI:
The caveat being that if you have to go get a bunch of data to create the record you are trying to insert (instead of passing it all to the workflow), you would need those blocks as well, in which case, the branch might make sense to only do all that work if the record doesn't already exist.
That explains things better. Coming from Make filters are different. I should have read the documentation better.
I like your alternative but am going to push through the exercise so I understand better branches.
When I have records in the data set, the branch is doing its job. However when there are not records it stops anyways.
My condition is getStoredEvents.data.length = 0
. When I have no records it is showing undefined. I actually want the branch to all the next block to fire. How could I change this to accommodate?
You need getStoredEvents.data.length == 0
. Using =
is for assignment where ==
or ===
is for comparison (which to use depends on circumstances of your code - see Equality comparisons and sameness - JavaScript | MDN).
Works as expected. Thank you.
@jg80 feel free to chime into this one if you have time.