<?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: Get dynamic property name in execute script in Support Questions</title>
    <link>https://community.cloudera.com/t5/Support-Questions/Get-dynamic-property-name-in-execute-script/m-p/206819#M168780</link>
    <description>&lt;P&gt;Thanks Matt ! This is exactly what I needed&lt;/P&gt;</description>
    <pubDate>Tue, 03 Apr 2018 16:35:40 GMT</pubDate>
    <dc:creator>felicien_cathe1</dc:creator>
    <dc:date>2018-04-03T16:35:40Z</dc:date>
    <item>
      <title>Get dynamic property name in execute script</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Get-dynamic-property-name-in-execute-script/m-p/206815#M168776</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I am trying to make a Javascript code for the executeScript processor and I wonder if it's possible to get the name of a custom property added from the executeSript Properties tab.&lt;BR /&gt;&lt;BR /&gt;I know that if I add a property "myProperty", I can access it from the script by using myProperty.getValue() (or with .evaluateAttributeExpressions() when needed).&lt;/P&gt;&lt;P&gt;But is it possible to find the key "myProperty" from inside the script ? &lt;BR /&gt;&lt;BR /&gt;I would like to do something like &lt;/P&gt;&lt;PRE&gt;for(i = 0 ; i &amp;lt; customProperties.length ; i++){
	propertyName = customProperties[i].getName()
	value = propertyName.getValue()
	//Do something with propertyName and its value
}&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;Thanks in advance !&lt;BR /&gt;Félicien&lt;/P&gt;</description>
      <pubDate>Fri, 30 Mar 2018 15:46:52 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Get-dynamic-property-name-in-execute-script/m-p/206815#M168776</guid>
      <dc:creator>felicien_cathe1</dc:creator>
      <dc:date>2018-03-30T15:46:52Z</dc:date>
    </item>
    <item>
      <title>Re: Get dynamic property name in execute script</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Get-dynamic-property-name-in-execute-script/m-p/206816#M168777</link>
      <description>&lt;A rel="user" href="https://community.cloudera.com/users/20284/feliciencatherin1.html" nodeid="20284"&gt;@Félicien Catherin&lt;/A&gt;&lt;P&gt;If I understand your question properly, you want to check all the attributes of a flow file and then take some action on that attribute. For this, you can use getAttributes() function in your script. This will return you a map with attribute name as key and attribute value as value. For example&lt;/P&gt;&lt;PRE&gt;flowFile = session.get() 

attrMap = flowFile.getAttributes()&lt;/PRE&gt;&lt;P&gt;You can iterate on the map to check if a certain property exists or not or whatever actions you may want to take.&lt;/P&gt;&lt;P&gt;Hope that helps!&lt;/P&gt;</description>
      <pubDate>Sat, 31 Mar 2018 12:31:50 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Get-dynamic-property-name-in-execute-script/m-p/206816#M168777</guid>
      <dc:creator>RahulSoni</dc:creator>
      <dc:date>2018-03-31T12:31:50Z</dc:date>
    </item>
    <item>
      <title>Re: Get dynamic property name in execute script</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Get-dynamic-property-name-in-execute-script/m-p/206817#M168778</link>
      <description>&lt;A rel="user" href="https://community.cloudera.com/users/20284/feliciencatherin1.html" nodeid="20284"&gt;@Félicien Catherin&lt;/A&gt;&lt;P&gt;Did the answer help in the resolution of your query? Please close the thread by marking the answer as Accepted!&lt;/P&gt;</description>
      <pubDate>Sun, 01 Apr 2018 22:27:26 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Get-dynamic-property-name-in-execute-script/m-p/206817#M168778</guid>
      <dc:creator>RahulSoni</dc:creator>
      <dc:date>2018-04-01T22:27:26Z</dc:date>
    </item>
    <item>
      <title>Re: Get dynamic property name in execute script</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Get-dynamic-property-name-in-execute-script/m-p/206818#M168779</link>
      <description>&lt;P&gt;You can access all the properties from the "context" variable, then filter on only the dynamic properties. You get a Map of PropertyDescriptors as keys to their values, so you can iterate over the keys to look for your property key(s). Here is a quick Groovy snippet that will log each dynamic property name:&lt;/P&gt;&lt;PRE&gt;context.properties.findAll {k,v -&amp;gt; k.dynamic}.each {k,v -&amp;gt; log.info(k.name)}&lt;/PRE&gt;</description>
      <pubDate>Mon, 02 Apr 2018 20:49:01 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Get-dynamic-property-name-in-execute-script/m-p/206818#M168779</guid>
      <dc:creator>mburgess</dc:creator>
      <dc:date>2018-04-02T20:49:01Z</dc:date>
    </item>
    <item>
      <title>Re: Get dynamic property name in execute script</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Get-dynamic-property-name-in-execute-script/m-p/206819#M168780</link>
      <description>&lt;P&gt;Thanks Matt ! This is exactly what I needed&lt;/P&gt;</description>
      <pubDate>Tue, 03 Apr 2018 16:35:40 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Get-dynamic-property-name-in-execute-script/m-p/206819#M168780</guid>
      <dc:creator>felicien_cathe1</dc:creator>
      <dc:date>2018-04-03T16:35:40Z</dc:date>
    </item>
    <item>
      <title>Re: Get dynamic property name in execute script</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Get-dynamic-property-name-in-execute-script/m-p/206820#M168781</link>
      <description>&lt;P&gt;Not really.. but Matt's answer is what I needed, thank for your answer anyway !&lt;/P&gt;</description>
      <pubDate>Tue, 03 Apr 2018 16:37:37 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Get-dynamic-property-name-in-execute-script/m-p/206820#M168781</guid>
      <dc:creator>felicien_cathe1</dc:creator>
      <dc:date>2018-04-03T16:37:37Z</dc:date>
    </item>
    <item>
      <title>Re: Get dynamic property name in execute script</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Get-dynamic-property-name-in-execute-script/m-p/206821#M168782</link>
      <description>&lt;P&gt;This is working perfectly with this groovy script. However, I wanted to do that in Javascript (since I want to manipulate JSON objects), is there an easy way to filter the dynamics properties ?&lt;BR /&gt;For now, I can retrieve the list of properties (in context.properties), but I don't see any difference between the "hard coded properties" ("script engine","script file", "modules directory") and the properties I added myself. &lt;/P&gt;&lt;P&gt;Thanks in advance if you can help&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Apr 2018 20:03:15 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Get-dynamic-property-name-in-execute-script/m-p/206821#M168782</guid>
      <dc:creator>felicien_cathe1</dc:creator>
      <dc:date>2018-04-03T20:03:15Z</dc:date>
    </item>
    <item>
      <title>Re: Get dynamic property name in execute script</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Get-dynamic-property-name-in-execute-script/m-p/206822#M168783</link>
      <description>&lt;P&gt;&lt;A rel="user" href="https://community.cloudera.com/users/641/mburgess.html" nodeid="641"&gt;@Matt Burgess&lt;/A&gt; &lt;/P&gt;</description>
      <pubDate>Thu, 05 Apr 2018 15:30:53 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Get-dynamic-property-name-in-execute-script/m-p/206822#M168783</guid>
      <dc:creator>felicien_cathe1</dc:creator>
      <dc:date>2018-04-05T15:30:53Z</dc:date>
    </item>
    <item>
      <title>Re: Get dynamic property name in execute script</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Get-dynamic-property-name-in-execute-script/m-p/206823#M168784</link>
      <description>&lt;P&gt;I used Groovy's findAll method for filtering/iterating in my example, you'd just have to use the Javascript idiom, maybe something like:&lt;/P&gt;&lt;PRE&gt;for(var pdMap in context.getProperties()) {&lt;BR /&gt;  if(pd.getKey().isDynamic()) {&lt;BR /&gt;    // This is a user-defined "dynamic" property, the ExecuteScript properties won't show up here&lt;BR /&gt;  }&lt;BR /&gt;}&lt;/PRE&gt;&lt;P&gt;Having said that, if you are only using Javascript in order to parse JSON, you can keep Groovy and use &lt;A href="http://docs.groovy-lang.org/latest/html/gapi/groovy/json/JsonSlurper.html" target="_blank"&gt;JsonSlurper&lt;/A&gt; and &lt;A href="http://docs.groovy-lang.org/latest/html/gapi/groovy/json/JsonOutput.html" target="_blank"&gt;JsonOutput&lt;/A&gt; and other handy classes for manipulating JSON objects.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Apr 2018 20:16:01 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Get-dynamic-property-name-in-execute-script/m-p/206823#M168784</guid>
      <dc:creator>mburgess</dc:creator>
      <dc:date>2018-04-05T20:16:01Z</dc:date>
    </item>
    <item>
      <title>Re: Get dynamic property name in execute script</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Get-dynamic-property-name-in-execute-script/m-p/206824#M168785</link>
      <description>&lt;P&gt;Thanks a lot ! , i'll have a look to JsonSlurper and JsonOutput &lt;/P&gt;</description>
      <pubDate>Thu, 05 Apr 2018 20:21:15 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Get-dynamic-property-name-in-execute-script/m-p/206824#M168785</guid>
      <dc:creator>felicien_cathe1</dc:creator>
      <dc:date>2018-04-05T20:21:15Z</dc:date>
    </item>
    <item>
      <title>Re: Get dynamic property name in execute script</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Get-dynamic-property-name-in-execute-script/m-p/206825#M168786</link>
      <description>&lt;P&gt;If anyone needs it (Matt answers helped me a lot but is not exactly correct) :&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;for(var prop in context.properties) {&lt;BR /&gt;  if(prop.isDynamic()) {
	var name = prop.getName();
	var value = context.getProperty(name).evaluateAttributeExpressions(flowFile).getValue();&lt;BR /&gt;	//or var value = context.getProperty(name).getValue(); if AttributeExpression are not needed
	log.info('name : ' + name + " value : " + value);
  }&lt;BR /&gt;}
&lt;/PRE&gt;</description>
      <pubDate>Thu, 05 Apr 2018 21:47:29 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Get-dynamic-property-name-in-execute-script/m-p/206825#M168786</guid>
      <dc:creator>felicien_cathe1</dc:creator>
      <dc:date>2018-04-05T21:47:29Z</dc:date>
    </item>
  </channel>
</rss>

