I've read everything out there on scripted parameters in FME (which is not much) and none of it has helped me.
I'm trying to have an AttributeRenamer, where the Attribute List is a scripted python parameter, a fairly simple one at that. Say, my original field is "ONE_AAA". (but it could be "TWO_AAA", "THREE_AAA", etc). I want it to rename it to just "AAA", so I have a this python script:
fld = FME_MacroValues['Test_Condition_1']
suffx = fld[(fld.find("_")+1):fld.__len__()]
return fld + ',' + suffx + ',""'
'Test_Condition_1' is simply a published parameter that the user enters to let FME know what field he wants renamed. I've linked this python scripted parameter to the Attribute List and it does not work. Can anyone tell me what I am doing wrong?
Best answer by david_r
I think your issue is more with the AttributeRenamer than with the Python scripted parameter here. In your place I would have dropped the scripted parameter and the AttributeRenamer altogether, replacing it with a PythonCaller with the following code:
Did this help you find an answer to your question?
This post is closed to further activity.
It may be a question with a best answer, an implemented idea, or just a post needing no comment.
If you have a follow-up or related question, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.
I think your issue is more with the AttributeRenamer than with the Python scripted parameter here. In your place I would have dropped the scripted parameter and the AttributeRenamer altogether, replacing it with a PythonCaller with the following code:
I thought about PythonCaller, but again documentation was very inadequate, so I wasn't sure where to begin with it. This might be the right way to go, but I still have some questions.
First of all, I think you misunderstood what I was trying to do. The field is named "ONE_AAA" in the table and I want to rename it to "AAA" (I'm not going from "ONE" to "AAA"). Because some fields can have more underscores after the initial prefix, I chose not to use the split() function.
Anyway, questions what do I put in as the entry point? Would that be just "DynamicAttributeRenamer", right? And am I exposing any attributes?
I just got your script to run and it doesn't do what I want. It's erasing my existing data and replacing it with "ONE" throughout the table. Maybe I worded what I was trying to do incorrectly. I do not want to change the data in the tables at all. I just want to change the field names from "ONE_AAA" to "AAA" and copy the data over from a different bit of logic I have that works fine.
Ok, after a big of messing around with the data, I got it to work. I had null values which was causing the script to crash my workspace and I had to handle it. This works great. Thanks David.
Though, I am still would love for someone to explain scripted parameters to me.
Scripted parameters are (published or private) parameters with a value that is calculated by a script rather than given as-is on the command line. They really aren't much more complicated than that.
Here is an example use case for a scripted parameter:
We use 3 different kinds of cookies. You can choose which cookies you want to accept. We need basic cookies to make this site work, therefore these are the minimum you can select. Learn more about our cookies.