<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Re: How can I get Nifi expression language to work with Properties added to ExecuteScript? in Archives of Support Questions (Read Only)</title>
    <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/How-can-I-get-Nifi-expression-language-to-work-with/m-p/119485#M26397</link>
    <description>&lt;P&gt;Dynamic properties (like your "testProperty") are passed in as variables, and they are PropertyValue objects. PropertyValue has a method called evaluateAttributeExpressions() and if you want to to resolve attributes from a FlowFile, you can pass in a reference to that flow file. Then you call getValue() (or just ".value" in Groovy) and the property will have been evaluated correctly.&lt;/P&gt;&lt;P&gt;Since you're using the "filename" attribute, I assume you will be getting that from an incoming flow file. So you will need to get the flow file from the session, pass it into evaluateAttributeExpressions(), then don't forget to transfer or remove the flow file. Here is an example in Groovy:&lt;/P&gt;&lt;PRE&gt;flowFile = session.get()
if(!flowFile) return 
log.info("-----------------------" + testProperty.evaluateAttributeExpressions(flowFile).value)
session.transfer(flowFile, REL_SUCCESS)&lt;/PRE&gt;</description>
    <pubDate>Thu, 28 Apr 2016 01:26:46 GMT</pubDate>
    <dc:creator>mburgess</dc:creator>
    <dc:date>2016-04-28T01:26:46Z</dc:date>
    <item>
      <title>How can I get Nifi expression language to work with Properties added to ExecuteScript?</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/How-can-I-get-Nifi-expression-language-to-work-with/m-p/119484#M26396</link>
      <description>&lt;P&gt;In an ExecuteScript processor, I added a property called testProperty and set the value to ${filename}. But when I reference it in my groovy script, I get "${filename}" rather than the value of the 'filename' in the incoming flowfile. ExecuteSripts says that properties support expression language, but I'm not seeing it.&lt;/P&gt;&lt;P&gt;My test script is simple and I watch the logs.&lt;/P&gt;&lt;P&gt;log.info(" -------------------------" + testProperty)&lt;/P&gt;&lt;P&gt;It prints this but filename is a pre-existing attribute:&lt;/P&gt;&lt;P&gt;-------------------------${filename}&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Thu, 28 Apr 2016 00:33:11 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/How-can-I-get-Nifi-expression-language-to-work-with/m-p/119484#M26396</guid>
      <dc:creator>james_jones</dc:creator>
      <dc:date>2016-04-28T00:33:11Z</dc:date>
    </item>
    <item>
      <title>Re: How can I get Nifi expression language to work with Properties added to ExecuteScript?</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/How-can-I-get-Nifi-expression-language-to-work-with/m-p/119485#M26397</link>
      <description>&lt;P&gt;Dynamic properties (like your "testProperty") are passed in as variables, and they are PropertyValue objects. PropertyValue has a method called evaluateAttributeExpressions() and if you want to to resolve attributes from a FlowFile, you can pass in a reference to that flow file. Then you call getValue() (or just ".value" in Groovy) and the property will have been evaluated correctly.&lt;/P&gt;&lt;P&gt;Since you're using the "filename" attribute, I assume you will be getting that from an incoming flow file. So you will need to get the flow file from the session, pass it into evaluateAttributeExpressions(), then don't forget to transfer or remove the flow file. Here is an example in Groovy:&lt;/P&gt;&lt;PRE&gt;flowFile = session.get()
if(!flowFile) return 
log.info("-----------------------" + testProperty.evaluateAttributeExpressions(flowFile).value)
session.transfer(flowFile, REL_SUCCESS)&lt;/PRE&gt;</description>
      <pubDate>Thu, 28 Apr 2016 01:26:46 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/How-can-I-get-Nifi-expression-language-to-work-with/m-p/119485#M26397</guid>
      <dc:creator>mburgess</dc:creator>
      <dc:date>2016-04-28T01:26:46Z</dc:date>
    </item>
    <item>
      <title>Re: How can I get Nifi expression language to work with Properties added to ExecuteScript?</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/How-can-I-get-Nifi-expression-language-to-work-with/m-p/119486#M26398</link>
      <description>&lt;P&gt;Awesome! Thanks for the full sample.&lt;/P&gt;&lt;P&gt;By digging through source code I figured out that I could use the property object with evaluateExpressions(flowFile), but I did not realize that testProperty is a property already. duh.&lt;/P&gt;&lt;P&gt;This is what I had tried but it printed "null", so assumed I was going down the wrong path.
&lt;/P&gt;&lt;PRE&gt;flowFile = session.get()
if(!flowFile) return
def retVal = context.getProperty('testProperty').evaluateExpressions(flowFile)
log.info("-----------------------"+retVal?.value)
session.transfer(flowFile, REL_SUCCESS)&lt;/PRE&gt;</description>
      <pubDate>Thu, 28 Apr 2016 02:15:18 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/How-can-I-get-Nifi-expression-language-to-work-with/m-p/119486#M26398</guid>
      <dc:creator>james_jones</dc:creator>
      <dc:date>2016-04-28T02:15:18Z</dc:date>
    </item>
  </channel>
</rss>

