Question

I have an attribute selecting parameter in a custom transformer and want to publish it - but the attribute is combined within a longer setting. How do I do this?

Answer

Problem

It can be difficult to publish an attribute selection from within a custom transformer. This problem frequently occurs with the Tester and ExpressionEvaluator transformers when used inside a custom transformer.

For example, in a Tester transformer you need to test where <attribute> = -999, the attribute is to be selected by the user and so you publish that parameter. However, you find that the actual parameter is a combination of the entire test: TEST @Value(<AttributeName>) = -999

You don't want the user to be prompted to entire the entire test value, just the attribute to test. How do you get around it?

Solution

There's a simple method to do this - you need to find a transformer that permits you to select an attribute that can be later used within the Tester. There are a couple that can do this...

1. SubstringExtractor

Place a SubstringExtractor and publish the source attribute. Set the start index=0 and end index =-1 to grab the entire published string. Set the result attribute to a new attribute name. Then in the Tester test for <newAttribute> = -999

Here the user has a custom transformer with an ExpressionEvaluator within it. He wishes to publish an attribute to be used within the expression, but cannot do so without publishing the entire expression. Here's his workaround...


User-added image
Above: The user places a SubstringExtractor, locates it in the navigation pane and publishes the Source Attribute parameter.


User-added image
Above: The published parameter setup dialog.


User-added image
Above: These are the transformer settings for the SubstringExtractor after publishing the source attribute parameter. Notice the new attribute called _parity


User-added image
Above: Instead of having to publish the ExpressionEvaluator expression, the user can now simply use the _parity attribute within the expression.


User-added image
Above: Back on the custom transformer the settings now include one to select an attribute.


NB: This is the exact method used in the example custom transformer AttributeParity.

2. Attribute Setter Approach

A similar solution can be obtained through a combination of the AttributeCreator and AttributeSetter. Simply create a new attribute in the AttributeCreator with any value. In the AttributeSetter choose the new attribute as the attribute to be set, and publish the value setting. This will be exposed as a value or attribute selection on the custom transformer - giving double the possibilities. 

3.  Use FME 2012 or later

In FME 2012, the value selection in the Tester (and all transformers) has changed.  Double-click on the Left Value or Right Value in the Tester, and click the down arrow.  You can now select a Link To Parameter option to create a published parameter directly from within the transformer.  Publish this parameter, and then in the workspace, publish that parameter from the custom transformer.