Support Questions

Find answers, ask questions, and share your expertise

Need to access and update a processor property

New Contributor

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.


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.

New Contributor

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.

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.

New Contributor

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.

Take a Tour of the Community
Don't have an account?
Your experience may be limited. Sign in to explore more.