<?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: Accessing processor properties in Execute Script in Archives of Support Questions (Read Only)</title>
    <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Accessing-processor-properties-in-Execute-Script/m-p/115476#M54962</link>
    <description>&lt;P&gt;Hi &lt;A rel="user" href="https://community.cloudera.com/users/595/alopresto.html" nodeid="595"&gt;@Andy LoPresto&lt;/A&gt; : I was asking about the dynamic properties set for the processor. Are they treated the same as attributes? I haven't tried accessing them by the getAttribute, will give it a try. &lt;/P&gt;</description>
    <pubDate>Tue, 21 Feb 2017 06:07:26 GMT</pubDate>
    <dc:creator>arunak</dc:creator>
    <dc:date>2017-02-21T06:07:26Z</dc:date>
    <item>
      <title>Accessing processor properties in Execute Script</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Accessing-processor-properties-in-Execute-Script/m-p/115474#M54960</link>
      <description>&lt;P&gt;
	Hi All, &lt;/P&gt;&lt;P&gt;	
I am using a JavaScript Execute Script Processor. However, I am missing a document that details on how to access the dynamic properties set on the processor within the script body. &lt;/P&gt;&lt;P&gt;	
Any help appreciated. &lt;/P&gt;&lt;P&gt;	
Thanks&lt;/P&gt;&lt;P&gt;	
-ak-&lt;/P&gt;</description>
      <pubDate>Tue, 21 Feb 2017 05:37:54 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Accessing-processor-properties-in-Execute-Script/m-p/115474#M54960</guid>
      <dc:creator>arunak</dc:creator>
      <dc:date>2017-02-21T05:37:54Z</dc:date>
    </item>
    <item>
      <title>Re: Accessing processor properties in Execute Script</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Accessing-processor-properties-in-Execute-Script/m-p/115475#M54961</link>
      <description>&lt;P&gt;
 Arun,&lt;/P&gt;&lt;P&gt;
 &lt;STRONG&gt;Edit&lt;/STRONG&gt;:&lt;/P&gt;&lt;P&gt;
 Sorry, I got this confused with another question I was answering at the same time. To access dynamic properties in the script body, just reference them as a variable name.&lt;/P&gt;&lt;P&gt;
 From 
 &lt;A target="_blank" href="https://funnifi.blogspot.com/2016/02/executescript-processor-hello-world.html" rel="nofollow noopener noreferrer"&gt;Matt Burgess' blog&lt;/A&gt;:&lt;/P&gt;&lt;BLOCKQUOTE&gt;
 Dynamic Properties:  Any dynamic properties defined in ExecuteScript are passed to the script engine as variables set to the string value of the property values. This means you must be aware of the variable naming properties for the chosen script engine. For example, Groovy does not allow periods (.) in variable names, so don't use something like "my.property" as a dynamic property name.
&lt;/BLOCKQUOTE&gt;&lt;P&gt;
 Here is the example output from a &lt;CODE&gt;LogAttribute&lt;/CODE&gt; processor following an &lt;CODE&gt;ExecuteScript&lt;/CODE&gt; processor where I update the flowfile by adding an attribute with the content of a dynamic property on the &lt;CODE&gt;ExecuteScript&lt;/CODE&gt; processor. &lt;/P&gt;&lt;P&gt;
 Processor config:&lt;/P&gt;&lt;P&gt;
 &lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="12716-screen-shot-2017-02-20-at-52405-pm.png" style="width: 1664px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/23089iA4611E815347E84C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="12716-screen-shot-2017-02-20-at-52405-pm.png" alt="12716-screen-shot-2017-02-20-at-52405-pm.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;
 Groovy script (note casting 
 &lt;CODE&gt;dynamic&lt;/CODE&gt; to &lt;CODE&gt;String&lt;/CODE&gt; because by default it is of type &lt;CODE&gt;org.apache.nifi.attribute.expression.language.StandardPropertyValue&lt;/CODE&gt;&lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;
&lt;PRE&gt;def flowfile = session.get()
if (!flowfile) return
log.info("Dynamic property value: ${dynamic as String}")
flowfile = session.putAttribute(flowfile, "dynamic", dynamic as String)
session.transfer(flowfile, REL_SUCCESS)
&lt;/PRE&gt;&lt;PRE&gt;2017-02-20 17:22:04,072 INFO [Timer-Driven Process Thread-3] o.a.n.processors.standard.LogAttribute LogAttribute[id=5e4107e1-015a-1000-5efa-735bf688a3d0] logging for flow file StandardFlowFileRecord[uuid=4edb12f2-a020-4c3e-b42b-0796b8e91031,claim=StandardContentClaim [resourceClaim=StandardResourceClaim[id=1487639391782-1, container=default, section=1], offset=725, length=29],offset=0,name=420715910236852,size=29]
--------------------------------------------------
Standard FlowFile Attributes
Key: 'entryDate'
 Value: 'Mon Feb 20 17:22:04 PST 2017'
Key: 'lineageStartDate'
 Value: 'Mon Feb 20 17:22:04 PST 2017'
Key: 'fileSize'
 Value: '29'
FlowFile Attribute Map Content
Key: 'dynamic'
 Value: 'This is the value of a dynamic processor property set by Andy.'
Key: 'filename'
 Value: '420715910236852'
Key: 'path'
 Value: './'
Key: 'uuid'
 Value: '4edb12f2-a020-4c3e-b42b-0796b8e91031'
--------------------------------------------------
This is the flowfile content.
&lt;/PRE&gt;&lt;P&gt;
 &lt;STRONG&gt;Original answer&lt;/STRONG&gt; (referencing attributes):&lt;/P&gt;&lt;P&gt;
 You extract them from the 
 &lt;CODE&gt;flowfile&lt;/CODE&gt; object and write them to the flowfile via the &lt;CODE&gt;session&lt;/CODE&gt; object. &lt;CODE&gt;flowfile.getAttribute(attribute_name)&lt;/CODE&gt; returns the &lt;CODE&gt;attribute_value&lt;/CODE&gt;, and &lt;CODE&gt;session.putAttribute(flowfile, attribute_name, attribute_value)&lt;/CODE&gt; returns the new &lt;CODE&gt;flowfile&lt;/CODE&gt; instance.&lt;/P&gt;&lt;P&gt;
 Example:&lt;/P&gt;
&lt;PRE&gt; flowFile = session.putAttribute(flowFile, "filename", flowFile.getAttribute('filename').split('.')[0]+'_translated.json')
&lt;/PRE&gt;</description>
      <pubDate>Mon, 19 Aug 2019 10:59:18 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Accessing-processor-properties-in-Execute-Script/m-p/115475#M54961</guid>
      <dc:creator>alopresto</dc:creator>
      <dc:date>2019-08-19T10:59:18Z</dc:date>
    </item>
    <item>
      <title>Re: Accessing processor properties in Execute Script</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Accessing-processor-properties-in-Execute-Script/m-p/115476#M54962</link>
      <description>&lt;P&gt;Hi &lt;A rel="user" href="https://community.cloudera.com/users/595/alopresto.html" nodeid="595"&gt;@Andy LoPresto&lt;/A&gt; : I was asking about the dynamic properties set for the processor. Are they treated the same as attributes? I haven't tried accessing them by the getAttribute, will give it a try. &lt;/P&gt;</description>
      <pubDate>Tue, 21 Feb 2017 06:07:26 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Accessing-processor-properties-in-Execute-Script/m-p/115476#M54962</guid>
      <dc:creator>arunak</dc:creator>
      <dc:date>2017-02-21T06:07:26Z</dc:date>
    </item>
    <item>
      <title>Re: Accessing processor properties in Execute Script</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Accessing-processor-properties-in-Execute-Script/m-p/115477#M54963</link>
      <description>&lt;P&gt;Thanks &lt;A rel="user" href="https://community.cloudera.com/users/595/alopresto.html" nodeid="595"&gt;@Andy LoPresto&lt;/A&gt;. This helps. &lt;/P&gt;</description>
      <pubDate>Tue, 21 Feb 2017 22:04:20 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Accessing-processor-properties-in-Execute-Script/m-p/115477#M54963</guid>
      <dc:creator>arunak</dc:creator>
      <dc:date>2017-02-21T22:04:20Z</dc:date>
    </item>
  </channel>
</rss>

