nifi-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Matt Burgess <mattyb...@apache.org>
Subject Re: Execute Script - Groovy get attribute
Date Wed, 03 Jun 2020 15:07:36 GMT
Asmath,

When you pass an integer argument into session.get(), you get an ArrayList
back, not a single FlowFile. You can just use session.get() to get (up to)
1 FlowFile, or if you call session.get(1) you can just use the first
element (once checking to see if it's null), so
trigger[0].getAttribute('cnt')

Regards,
Matt


On Wed, Jun 3, 2020 at 8:58 AM KhajaAsmath Mohammed <mdkhajaasmath@gmail.com>
wrote:

> Hi,
>
> I have followed the below link to wait for 100 files and then process the
> next step.
>
>
> https://community.cloudera.com/t5/Support-Questions/NiFi-Count-Fileflows-via-attribute/td-p/178860
>
>
> This works well but my use case is that count number is dynamic. To test
> the functionality, I have passed an attribute count to get the value. Below
> script is not working. any help?
>
> import org.apache.commons.io.IOUtils
> import java.nio.charset.StandardCharsets
> def trigger=session.get(1)
> def flowFiles=session.get(99)
> if (!trigger) return
>
> *String attr=trigger.getAttribute("cnt");*
>
>
> if(!flowFiles || flowFiles.size() < 7)
> {
> session.rollback()
> }
> else
> {
> session.transfer(trigger,REL_SUCCESS)
> session.transfer(flowFiles,REL_FAILURE)
>
> }
>
> [image: image.png]
>
> Here is the error I got.
>
> Thanks,
> Asmath
>

Mime
View raw message