In a custom transformer I have to use a published parameter in a couple of places. The parameter is passed from the Main workspace. I inspected with loggers and I realised that the value is present at the beginning of the custom transformer workflow but when proceeding along it gets wiped out ( I don't know what causes this, as far as I knew published parameters are read-only).
I guess the parameter is in the Initiator output that you are not using. Could you check?
I guess the parameter is in the Initiator output that you are not using. Could you check?
You're correct that Published Parameters are read only. They are set when you press the run button and don't/can't change during translation.
So... I'm wondering where and how you get the published parameter and log its contents. I'm seeing VariableRetriever transformers, which always makes me wonder. They depend on the flow of features being exactly as you expect, and this is not always the case.
Oh, I wonder... When creating a custom transformer there is the option to have FME handle all used attributes using parameters. If you do that, then FME creates a published parameter, but you aren't expected to use it. You're expected to use the attribute name, regardless of what is entering. FME automatically replaces the value with the parameter when run.
For example, I have a LabelPointReplacer transformer that creates a label using an attribute called MyAttr1. If I create a custom transformer from this, then FME generates a user parameter in that transformer called MYATTR1. However, the LabelPointReplacer still points to the attribute called MyAttr1. FME carries out a substitution at run time.
Even if I go back to the main canvas, and change the Custom Transformer parameter to use MyAttr2, the LabelPointReplacer inside the custom transformer still says it is using MyAttr1. In reality that's still linked to the MYATTR1 parameter, which now points to MyAttr2.
I wonder if you're looking at a user parameter that was generated inside the custom transformer. It's better to use the attribute it points to, not reference that parameter. I wonder if that's why you aren't getting the value you are expecting.
You're correct that Published Parameters are read only. They are set when you press the run button and don't/can't change during translation.
So... I'm wondering where and how you get the published parameter and log its contents. I'm seeing VariableRetriever transformers, which always makes me wonder. They depend on the flow of features being exactly as you expect, and this is not always the case.
Oh, I wonder... When creating a custom transformer there is the option to have FME handle all used attributes using parameters. If you do that, then FME creates a published parameter, but you aren't expected to use it. You're expected to use the attribute name, regardless of what is entering. FME automatically replaces the value with the parameter when run.
For example, I have a LabelPointReplacer transformer that creates a label using an attribute called MyAttr1. If I create a custom transformer from this, then FME generates a user parameter in that transformer called MYATTR1. However, the LabelPointReplacer still points to the attribute called MyAttr1. FME carries out a substitution at run time.
Even if I go back to the main canvas, and change the Custom Transformer parameter to use MyAttr2, the LabelPointReplacer inside the custom transformer still says it is using MyAttr1. In reality that's still linked to the MYATTR1 parameter, which now points to MyAttr2.
I wonder if you're looking at a user parameter that was generated inside the custom transformer. It's better to use the attribute it points to, not reference that parameter. I wonder if that's why you aren't getting the value you are expecting.
Actually I am confronted with this issue lately since last update.
I have a lot of scripts passing values trough published parameters.
They now come up empty. Unless i actually retrieve them into attributes (as @Mark2AtSafe points out)
I had to change a couple of workbenches after is (no comment please) is saved them with no backup..
BTW if we focus again on the fact that the parameter exists and then it stops existing and it is a read only element, then there is surely something in the above statement is not true...how can something which is read only become blank? The logger is put to testify that actually the parameter is wiped out, it has no relevance on the actual translation, the parameter is wiped out regardless of the logger
I understand all the points you make in your answer, they would apply to my case if the published parameter would not exist at all in the custom transformer, in my case it exists and then it ceases to exist with no apparent reason (to me), and again if we assume published parameter are read only then parameters should be global, parameters should not change.
If needed I could be in touch with someone from support and upload the whole workbench, your help would be appreciated. Or send it to you via a private channel
So, I think the confusion is because when you create a custom transformer, it is like having a separate workspace. It has its own parameters and they are different to those in the main workspace. So a parameter does keep its value (they are most definitely read-only), but I suspect you are looking at two different parameters.
I made a short video to demonstrate that fact: https://www.screencast.com/t/QHJKlRk2bcO2
So I have $(MyName) in the main workspace and what looks like $(MyName) in the custom transformer. But under the hood in FME, the actual name of the parameter in the custom transformer is $(TransformerName_WorkspaceName)_MyName.
What I think is that you are setting $(MyName) in the main workspace and not in the custom transformer. When you read $(MyName) in the workspace it has a value, but when you try to read it in the custom transformer, then FME says it is empty. That's because FME is replacing $(MyName) to $(TransformerName_WorkspaceName)_MyName and returning a different parameter value.
I know this can be confusing, and maybe I have not described it very well (try the video and things will be clearer). But in short, the point is this. If you want a user to set a value of a parameter at run time, and have it available in the custom transformer, then what you do is this:
- Create the parameter *inside* the custom transformer
- In the main tab, open the custom transformer's parameters dialog
- Select your new parameter, and turn that into a new user parameter
Now the two are linked. In my video, Workspace:MyName_2 is linked to Transformer:MyName1. Whatever the user enters into the workspace (MyName_2) at run time, is passed to the custom transformer (MyName).
I hope this helps to explain. Also, you are correct about fme_feature_type. It is an attribute (not a parameter) and so it can change. When you use a FeatureReader transformer then the output is tagged with the feature type it was read from in the FeatureReader. The "Initiator" features will retain the fme_feature_type value they had already.