Archives of Support Questions (Read Only)

This is an archived board for historical reference. Information and links may no longer be available or relevant
Announcements
This board is archived and read-only for historical reference. To ask a new question, please post a new topic on the appropriate active board.

Get dynamic property name in execute script

avatar

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

1 ACCEPTED SOLUTION

avatar
Master Guru

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)}

View solution in original post

10 REPLIES 10

avatar

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); }
}