Support Questions

Find answers, ask questions, and share your expertise

NiFi: Is it possible to access Processor Group variables within ExectueScript?

avatar
Contributor

Hey Guys,

Is it possible to access the Processor Group variables within the ExecuteScript Processor? I would specifically be interested in the syntax for doing that with Ruby.

Any guidance would be appreciated.

1 ACCEPTED SOLUTION

avatar
Master Guru

The variables are in a ComponentVariableRegistry which is pretty well-hidden under the NiFi API. Usually you get at variables by evaluating Expression Language in the context of a processor property. In this case I set a Process Group variable called "myAttr" to "myValue", then I configured ExecuteScript like so:

77400-useprocessgroupvariable.png

Note that I created a user-defined property "myProp" whose value is an expression language construct containing the PG variable name. When you call evaluateAttributeExpressions() on that property (see the script) it will resolve the value of "myAttr" and return that, you can verify that an outgoing flow file would now have "myFlowFileAttr" set to "myValue".

View solution in original post

3 REPLIES 3

avatar
Master Guru

The variables are in a ComponentVariableRegistry which is pretty well-hidden under the NiFi API. Usually you get at variables by evaluating Expression Language in the context of a processor property. In this case I set a Process Group variable called "myAttr" to "myValue", then I configured ExecuteScript like so:

77400-useprocessgroupvariable.png

Note that I created a user-defined property "myProp" whose value is an expression language construct containing the PG variable name. When you call evaluateAttributeExpressions() on that property (see the script) it will resolve the value of "myAttr" and return that, you can verify that an outgoing flow file would now have "myFlowFileAttr" set to "myValue".

avatar
Contributor

Thanks Matt, that did the trick!

avatar
New Contributor

Is there a way (without using execute script) to modify the processor_group variable in processor?