According to several solved questions in this forum, there are two recommended ways to automatically remove attributes that only conatain NULL or empty values: using a small python script or using the NullAttributeMapper. Unfortunately both suggestions do not work for me (FME Desktop/Form 2022.2). Both the PythonCaller and the NullAttributeMapper keep the Null-Attributes and they are present when I write to Excel (see attached workspace). Is there something wrong in my workflow or is there an updated solution? Thanks for any suggestions!
As you're looking to dynamically change the schema (ie the schema is dependent/defined by the data) your going to need to follow a dynamic workflow where you make use of schema attributes and dynamic writers
https://community.safe.com/s/article/dynamic-workflow-tutorial-introduction
To achieve what your looking for, i've made a minor addition to the Python in the SchemaSetter custom transformer - https://hub.safe.com/publishers/safe-lab/transformers/schemasetter
In the uploaded workbench, you can see the changes i've made on lines 84-86. All my change does is that if the attribute does not have a value, it will exclude it from the schema creation. It then flows into a dynamic writer that uses the schema list on the attribute to define the excel sheets output fields
Hi @hkingsbury , thank you! Your modified Python code now removes all unused attributes. I also found out, that you could also use the SchemaScanner to achieve the same result (also using a dynamic writer). You just have to set it to "Ignore empty attributes" and exclude the schema attributes starting with fme_ (which is basically what you did in your script). I attached both solutions in case anyone needs this as a reference in the future.
Hi @hkingsbury , thank you! Your modified Python code now removes all unused attributes. I also found out, that you could also use the SchemaScanner to achieve the same result (also using a dynamic writer). You just have to set it to "Ignore empty attributes" and exclude the schema attributes starting with fme_ (which is basically what you did in your script). I attached both solutions in case anyone needs this as a reference in the future.
Good to know re the SchemaScanner, I don't deal with dynamic processes all that much and haven't had the chance to use that yet, but will investigate it further :)
Hmmm, I don’t sorry. But looking at the custom transformer, around those lines:
I imagine I was checking the value of att and only passing it through if it wasn’t none/null/empty