Created 03-30-2018 08:46 AM
Hi,
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.
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).
But is it possible to find the key "myProperty" from inside the script ?
I would like to do something like
for(i = 0 ; i < customProperties.length ; i++){ propertyName = customProperties[i].getName() value = propertyName.getValue() //Do something with propertyName and its value }
Thanks in advance !
Félicien
Created 04-02-2018 01:49 PM
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:
context.properties.findAll {k,v -> k.dynamic}.each {k,v -> log.info(k.name)}
Created 04-05-2018 02:47 PM
If anyone needs it (Matt answers helped me a lot but is not exactly correct) :
for(var prop in context.properties) {
if(prop.isDynamic()) { var name = prop.getName(); var value = context.getProperty(name).evaluateAttributeExpressions(flowFile).getValue();
//or var value = context.getProperty(name).getValue(); if AttributeExpression are not needed log.info('name : ' + name + " value : " + value); }
}