04-25-2017 10:07 PM
A common integration pattern is to do something when no data is received. For example, we might read a file, parse it, and find that no records meet some filter criteria. As a result, we might send an email, or insert a ticket into a ticket management system like ServiceNOW.
However, in SnapLogic, this can be somewhat more difficult than it seems initially because of the streaming architecture. In fact, many snaps will not execute without input documents - rather hard to accomplish when there is no document to flow through:
So, how can we take an action, even though there’s no document to run the snap?
The trick is to make a document and force it into the stream with a Join Snap
(set to Merge):
Note in this figure that even though nothing flows into the top view of the Join
Snap, it still produces an output.
This enables us to use the Router
snap to check whether or not a field that we know will exist in the source does in fact exist. If it does, we know that data has passed through the Filter
snap and then been merged with the Sequence
data. If it does not, we know that only the Sequence
data has been passed through and therefore nothing made it through the Filter
. Only one of these views will have anything pass through it.
The magic here is in the Merge option in the Join
snap. As long as it is receiving data on a view, it will output - even if it has nothing to ‘join’ to. Meanwhile, the Sequence
snap will always output the number of documents that you set it to. In this case, only one is required.
(This pipeline here: Do something after no doc filter_2017_04_26.slp (11.1 KB) )
02-22-2021 03:24 AM
" This enables us to use the Router
snap to check whether or not a field that we know will exist in the source does in fact exist "
Well what happen if we are not sure which field is coming out of source i.e field name is not fixed ?
02-23-2021 04:02 PM
You can use eval()
to dynamically check for the existence of a property.
This expression $.hasOwnProperty(eval('$dynamicKey'))
checks for the existence of the key dynamicKey
in the input document.
05-31-2022 09:41 AM
hey I also tried using the
so had a doubt will this cause it to execute this snap multiple time?
03-06-2023 08:51 PM
@ash42 this will not cause the snap to execute multiple times. What you see there means that the snap before this is passing multiple documents TO the router. The router will “route” the multiple documents downstream according to the rules configured in the router.
11-10-2023 05:36 AM
Hello,
Thanks for the solution. I use it in some cases.
But I have a pipe where the datasource are variables (queries on a DB). In that case, it could not work.
Do you have any idea ?
Thanks.