cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Performing an Action when there is no data

ncrouch
Former Employee

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:
0009551e1aa0ae88952d21fed89d11c27601ac83.png

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):
9d8ad9e24b2954b4dc66922f66f086d20b03fb6f.png
73eeae9d226276e393707cc64ae6c08873b03b7b.png
3a494da1ff3b5a4737a8f7ccd3ccf70903ec211a.png
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) )

14 REPLIES 14

nganapathiraju
Former Employee

Why use the filter in first place? You can use the router to achieve the same functionality as the filter.

Whatever continues from filter can be passed through one branch of the router. The other branch can handle the non-filtered data.

I am assuming you dont want to take the same action on both filtered and unfiltered data. Your actions will be different based on the data whether it meets your filter criteria.

If you want to perform an action If and Only If no data is returned as a result of an action, youโ€™ll need this.

In essence, youโ€™re saying โ€œif nothing matches this filter, do (thing)โ€. Itโ€™s necessary because if you have a situation where no data is returned from a snap (whether a filter or a router or a REST Get or a SQL Select or โ€ฆ), the snaps following will not execute at all. This gives you the ability to handle that situation.

I see your point. This is definitely a nice way since our platform is a streaming platform.!!

dmiller
Admin Admin
Admin

Thanks @ncrouch. Iโ€™ve been meaning to add this functionality to one of my pipelines and hadnโ€™t got around to it yet. This saved me some time. ๐Ÿ™‚

ec808c7a4be285bbc2d0e7f3f856d55e3efeae67.png


Diane Miller
Community Manager