Created on 10-10-2018 01:04 PM - edited 08-17-2019 09:08 PM
Hi, I need create groovy script to count th fileflows, this is my script:
def trigger = session.get() def flowFiles = session.get() if(flowFiles.size() < 9) { session.transfer(flowFiles,REL_SUCCESS) }else { session.transfer(flowFiles, REL_FAILURE) }
I want launch a script if de fileflow files are < 9.
But the error is:
Created 10-10-2018 03:46 PM
session.get() only returns a FlowFile reference (or null if one is not available). Instead you want something like
session.get(9)
which will return a List<FlowFile> guaranteed not to be null, but it may have size < 9 so your check should work in this case. Having said that, are you sure you want to transfer them to failure? If you're planning on just routing them back to the ExecuteScript (until 9 are available) then you could just do session.rollback() or session.transfer(flowFile, Relationship.SELF)
Created 10-15-2018 06:59 PM
I'm not sure if I fully understand how your downstream flow would work when there are < 9 flow files available to ExecuteScript, but here's something to try (note that you can use anything greater than 9 in place of the "10" below):
def flowFiles = session.get(10)
if(flowFiles.size() >= 9) {
session.remove(flowFiles)
} else {
session.transfer(flowFiles, REL_SUCCESS)
}
Created 02-13-2022 10:50 AM
Hi @mburgess
Is there a way to get the number of the files in the input then assign the count value to an attribute and assign a number value to each file
I have files to merge using MergeContent so I should assign fragment.index for each file and fragment.count as total count of files to merge.
Created 02-13-2022 11:14 PM
@yamaga, as this is an older post, you would have a better chance of receiving a resolution by starting a new thread. This will also be an opportunity to provide details specific to your environment that could aid others in assisting you with a more accurate answer to your question. You can link this thread as a reference in your new post.
Regards,
Vidya Sargur,Created 10-15-2018 11:35 AM
I just want to create a groovy script that counts the fileflows and if there is less than 9 run a script shell.
Thanks
Created 10-15-2018 06:54 PM
What about if there are zero available? Are you scheduling this processor to run every few seconds, or the default (as fast as possible)? If the latter, you will likely want to check that there are > 0 and < 9 flow files available.
Created 12-08-2018 01:49 AM
@Matt BurgessI had the similar scenario where i needed the count of flowfiles generated but the script is not working.The incoming queue is queued with the flowfiles and its not getting processed.Is it because its a clustered nifi.Can you please help?