Support Questions

Find answers, ask questions, and share your expertise

RouteOnAttribute Expression for Today's Date - NIFI

avatar
New Contributor

Hi everyone, 


I want to use a RouteOnAttribute to only pick up files with the current date. What expression can I use to achieve this? 

 

The files in the SFTP I am fetching from are suffixed with a date as follows: 

 

_2020_11_04_06_37

_YYYY_MM_DD_HH_MM


Thanks!

 

3 REPLIES 3

avatar
Super Guru

@Makaveli  The solution you are looking for here is updateAttribute to create your string of the date format you want.  todayString = 

{now():format('YYYY_MM_dd_mm')} 

Then in routeOnText you use this attribute like this:  newRoute = 

 

${filename:endsWith(_${todayString}}

 

If this answer resolves your issue or allows you to move forward, please choose to ACCEPT this solution and close this topic. If you have further dialogue on this topic please comment here or feel free to private message me. If you have new questions related to your Use Case please create separate topic and feel free to tag me in your post.

 

Thanks,

Steven

avatar
New Contributor

@stevenmatison thanks for the reply. So you're saying from my LISTSFTP processor I should connect a UpdateAttribute processor with the expression you mentioned, then have a RouteText processor connected to the UpdateAttribute processor? 

 

I tried the above and the UpdateAttribute is picking up all files in the SFTP regardless of the date today, any recommendations? 

 

Thanks

avatar
Super Guru

@Makaveli  You can use File Filter Regex in ListSFTP to control which files come out of this processor.   Otherwise, you need to use ListSftp->UpdateAttribute->RouteOnAttribute to make sure the file name ends as suggested above.  Once you have a solid route of the files you want, then connect to FetchSFTP.