Created 06-19-2018 01:28 PM
I have an ExecuteScript processor that needs to add an attribute to an outgoing flowfile (JSON). However, i need that attribute's value to increment. I've tried to access the processor's property (myAttribute) via (var myAttr = session.getAttribute(flowfile, 'myAttribute')), but the non-zero value is never retrieved. I want to increment that value and then put it back into the processor (here, I tried session.putAttribute(flowfile, "myAttribute", myAttr + 1), as well as add it to the outgoing JSON.
Created 06-19-2018 04:45 PM
It is not clear whether you are talking about processor properties or flow file attributes, these are two different things.
A flow file attribute is retrieved using session.getAttribute
A processor property value is retrieve by using context.getProperty(NAME)
While a processor is running, you cannot change it's properties, you can only obtain the values using the context.
Created 06-19-2018 04:54 PM
Thanks, Bryan. I was talking about a processor property,. I wanted to add the value of that property to a JSON record as an attribute, incrementing that value in each flowfile record the ExecuteScript receives. I'll have to determine another way to 'persist' a value between executions of the processor.
Created 06-19-2018 06:40 PM
If you want the value to persist for the liftetime of the processor across restarts of NiFi, then you will want to use the state manager, example:
If you only care about the value from the time the processor is start until it is stopped, then you can just have a simple member variable of the processor hold an integer counter or whatever type.
Created 06-19-2018 08:02 PM
Appreciate the feedback. After your first answer I decided to go a slightly different way. I can insert a timestamp as another JSON element and use that. I can then use that column later in QueryDatabaseTable so that I retrieve only new rows in the target table. That seems to work fine.