I want to use the same condition for each attribute, with the only variation being the attribute/field name of the attribute to which the condition applies.
Yes, you can use @CurrentAttribute() so you can then use the same conditional statement multiple times without having to edit
Yes, you can use @CurrentAttribute() so you can then use the same conditional statement multiple times without having to edit
Brilliant, thank you for that!
Yes, you can use @CurrentAttribute() so you can then use the same conditional statement multiple times without having to edit
Thanks ebygomm, however my understanding is that "@CurrentAttribute()" refers to the value held by the attribute and not the attribute name. In your example you're testing whether "Attribute1" or "Attribute2" holds a value of "10". For my scenario, I'm hoping there's a similar method in relation to the current attribute name (i.e. "Attribute1", "Attribute2" - without specifying "Attribute1" or "Attribute2" in the condition statement).
I'm struggling to understand what you are trying to do. At the point you are writing the condition you know the attribute name, it's not variable.
If you want to do something to all attributes where the name matches certain criteria, you could look at the NullAttributeMapper, which despite the name will let you apply the same condition to multiple attributes depending on them matching a regex condition for example
The attached screen print shows an example of the condition that I would like to use against different attributes. The text highlighted in yellow is where the attribute name is specified. Rather than changing this text each time the condition is used, I was wondering if there's a was to generically reference the current attribute name. I need to use the condition many times for many different attributes (around 1,000). If I could generically reference the name of the current attribute, it'd make my job much easier. The alternative is to modify this part of the condition for each different attribute.
I think you will need to incorporate the AttributeExploder somehow. You will likely need to use the List option, and Keep Attributes. This transformer will allow you to test for the string in the attribute names, not just the attribute values. It's hard to say exactly what the workbench needs to look like, but this should point you in the right direction.
The attached screen print shows an example of the condition that I would like to use against different attributes. The text highlighted in yellow is where the attribute name is specified. Rather than changing this text each time the condition is used, I was wondering if there's a was to generically reference the current attribute name. I need to use the condition many times for many different attributes (around 1,000). If I could generically reference the name of the current attribute, it'd make my job much easier. The alternative is to modify this part of the condition for each different attribute.
Ah, now I understand. I'd probably resort to python for this
import fme
import fmeobjects
def processFeature(feature):
attrs = feature.getAllAttributeNames()
#get all attribute names as a list
label = feature.getAttribute('GISLabel')
#get value of attribute GISLabel and store as label
for a in attrs:
#for each attribute name in the list, if the attributename equals value of label
if a == label:
#set the value of the attribute to the value of the attribute AttributeDesc
feature.setAttribute(a,feature.getAttribute("AttributeDesc"))
else:
pass
Thanks ebygomm and ddbrocatto. I decided to give up trying to use the attribute name. Instead I modified my workflows such that the attributes first held their respective names as values and then used @CurrentAttribute() in the subsequent AttributeManager condition to replace the value with the value I needed. It allows me to use the same condition multiple times, so ultimately achieves the goal.
I’m facing a similar situation. I want to compare incoming attribute names against a list of reserved keywords from my database to make sure that the attribute name does not conflict.
You could take the schema or the schemaScanner to get a list of all the Attribute names. Then do a listSearcher to search the list for invalid names, but then you have to use a listSearcher for every invalid name I think.
With a few adaptations the Python Script Abygomm provided is a nice solution. Change If a == label: to a Python code that checks if a is in a list you provide and output an attribute that contains a notification that the data should be changed.
Or maybe you could use a BulkAttributeRenamer with a regex containing all reserved names and prefix or suffix all reserved names. Most of the time adding a prefix or suffix will fix.
That would be the easy fix.