Skip to main content
Solved

How to extract Custom Transformer Name from inside the Custom Transformer?


stipica.pavicic
Participant
Forum|alt.badge.img

I'm building a workflow that has error handling system in it. The idea is to send a message to the client about some specific error. To do that I've created a Custom Transformer that sends message.

 

It would be very handy to extract the Transformer Name and send it as a Error Code. In that way I can avoid typing an Error Code as a parameter value.

 

 

On the attached image you can see an example where ER000n are instances of the same Custom Transformer. I wonder is it possible to extract whatever was used as a Name of the transformer (ERR0006, ERR0007, etc.) form inside transformer? Extracted name will be a part of the Error Message that I'm sending to user.

 

 

Thanks

 

 

Best answer by jdh

So what you want is the custom transformer instance name,  not the custom transformer name.

You can get that via one of two hacks.

 

 

Using a pythonCaller inside the customa transformer.

 

With a FeatureProcessor object,   self.factory_name  is {custom transformer instance name}_{PythonCaller instance name}.
class FeatureProcessor(object):
    def __init__(self):
        pass
    def input(self,feature):
        feature.setAttribute("Name", self.factory_name[:-13])
        self.pyoutput(feature)
    def close(self):
        pass

 

where the length of the slice depends on the name of the pythonCaller transformer

 

 

If you want to avoid python

Inside the custom transformer  you can use a ParameterFetcher set to {TransformerName}_WORKSPACE_NAME.

 

So if the custom transformer was called ERR then you would set it to ERR_WORKSPACE_NAME,  and it would return ERR006.  The reason it's a hack, is that the parameter name is considered invalid.  You will get the red wheel, but if you ignore it and run the workspace anyhow it works.

 

 

 

View original
Did this help you find an answer to your question?

6 replies

jdh
Contributor
Forum|alt.badge.img+28
  • Contributor
  • Best Answer
  • November 7, 2019

So what you want is the custom transformer instance name,  not the custom transformer name.

You can get that via one of two hacks.

 

 

Using a pythonCaller inside the customa transformer.

 

With a FeatureProcessor object,   self.factory_name  is {custom transformer instance name}_{PythonCaller instance name}.
class FeatureProcessor(object):
    def __init__(self):
        pass
    def input(self,feature):
        feature.setAttribute("Name", self.factory_name[:-13])
        self.pyoutput(feature)
    def close(self):
        pass

 

where the length of the slice depends on the name of the pythonCaller transformer

 

 

If you want to avoid python

Inside the custom transformer  you can use a ParameterFetcher set to {TransformerName}_WORKSPACE_NAME.

 

So if the custom transformer was called ERR then you would set it to ERR_WORKSPACE_NAME,  and it would return ERR006.  The reason it's a hack, is that the parameter name is considered invalid.  You will get the red wheel, but if you ignore it and run the workspace anyhow it works.

 

 

 


stipica.pavicic
Participant
Forum|alt.badge.img

Fantastic :)

 

Thanks for help.

 

I prefer solution with the PythonCaller but the other method works also well.

 

 

The only drawback with the ParameterFetcher is that the transformer shows an error, however the workspace runs well with no errors and the results are good. Is it possible to get rid of the read error symbol on the transformer?

 

Thanks!!!

 

 


jdh
Contributor
Forum|alt.badge.img+28
  • Contributor
  • November 7, 2019
stipica.pavicic wrote:

Fantastic :)

 

Thanks for help.

 

I prefer solution with the PythonCaller but the other method works also well.

 

 

The only drawback with the ParameterFetcher is that the transformer shows an error, however the workspace runs well with no errors and the results are good. Is it possible to get rid of the read error symbol on the transformer?

 

Thanks!!!

 

 

That's the reason I called it a hack and not a solution. There's nothing we can do to make the parameter valid. It would require a change to the software.

 

 

Maybe post an idea along the lines of "FME Macro Values should be valid parameter names in the ParameterFetcher"

stipica.pavicic
Participant
Forum|alt.badge.img
stipica.pavicic wrote:

Fantastic :)

 

Thanks for help.

 

I prefer solution with the PythonCaller but the other method works also well.

 

 

The only drawback with the ParameterFetcher is that the transformer shows an error, however the workspace runs well with no errors and the results are good. Is it possible to get rid of the read error symbol on the transformer?

 

Thanks!!!

 

 

Thanks, both hacks are great :)


helmoet
Forum|alt.badge.img+8
  • November 8, 2019

Wow, great solutions. Would a VariableSetter/VariableRetrieve combination work as well?


jdh
Contributor
Forum|alt.badge.img+28
  • Contributor
  • November 8, 2019
helmoet wrote:

Wow, great solutions. Would a VariableSetter/VariableRetrieve combination work as well?

Not that I am aware of? How would get the value to set in the VariableSetter?


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings