2

I have an Excel reader in my workspace that have 2 attributes (CurrentName and NewName). The value of "CurrentName" shows a list of attribute names in the another reader that already are exist in my work space and the value of "NewName" shows a list of attribute names that must be create in the workspace.

I want to create new attributes that their name comes from "NewName" value and the value of new attributes comes from the another attribute that the name of it is similar to "CurrentName" value , for example:

I have this Excel file:

enter image description here

and add this file to my FME workspace as a dataset (reader1). In my Workspace I have another reader (reader2) that has "id" and "technology" attributes. So I want to create "NAME" and "MODEL" attributes in reader2 with the exact value of "id" attribute for the value of "NAME" attribute and the value of "technology" attribute for the value of "MODEL" attribute.

How can I do that in FME? Is there any transformer to do that?

1 Answer 1

2

Actually, once you have the right transformer this is very simple to do.

The transformer to use is a SchemaMapper. You don't even need a reader to read the Excel spreadsheet, it just gets referenced in the SchemaMapper.

  • Add a reader for your data (reader2 in your question)
  • Connect the reader to a SchemaMapper
  • In the SchemaMapper parameters wizard:
    • Set the format to Excel and pick the dataset
    • Select the sheet to use
    • Click the + button and select Attribute Map
    • In the dialog that opens select Current Name as the Source Field
    • Select NewName as the Destination Field
    • Choose whether to keep/remove the original attributes

Then close the dialogs (OK/finish) and run the workspace. The attributes will be renamed according to the lookup table in Excel.

Here's what the attribute map dialog looks like:

enter image description here

Now, there is one "gotcha" to mention. The attributes you have renamed everything to aren't automatically exposed in the workspace. i.e. you won't see NAME and MODEL unless you use the AttributeExposer on them. But they are there (and a Logger transformer would prove that).

And, of course, if you want them written out you need to have them on the writer somewhere too. If they might change in the Excel file, and you don't want to have to edit the workspace, then that would need to be a dynamic translation (check out examples on the knowledgebase at knowledge.safe.com)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.