Skip to main content
Question

Dynamically expose attributes

  • July 23, 2024
  • 5 replies
  • 761 views

hnahoulder
Contributor
Forum|alt.badge.img+2

I have a workflow that includes transformers and a Python caller. The output of the Python caller generates CSV, GeoJSON, and SHP writers. The workflow has a user parameter called OUTFIELDS, which specifies the fields that should be written. How can I achieve this? I tried using AttributeExploder, but I couldn't dynamically generate the list of fields.

5 replies

joepk
Influencer
Forum|alt.badge.img+20
  • Influencer
  • July 23, 2024

Edit: It seems I misread your post

Hi, I always use a PythonCaller to expose attributes stored in a User Parameter:

This can also be done in a FeatureReader


Hope this helps!


hnahoulder
Contributor
Forum|alt.badge.img+2
  • Author
  • Contributor
  • July 23, 2024

Thank you for your response. I have already tried setting the user parameter for the Attribute to expose. During execution, I set $(OUTFIELDS) to "OBJECTID MILLESIME_DATA MILLESIME_DATA2", and I get all three fields in my output. However, when I change the value of $(OUTFIELDS) to "OBJECTID MILLESIME_DATA", I still see all three fields instead of just the two specified. Therefore, I'm looking for an alternative solution, if possible.


nielsgerrits
VIP
Forum|alt.badge.img+61

I think the way to do this is to use dynamic writing (define the attributes based on a schema feature).

One way to do this is to use the SchemaScanner to generate a SchemaFeature. You will then need to remove the attributes from the schema feature which are not in the outfields parameter.

===

Attached sample demonstrating this.

 


joepk
Influencer
Forum|alt.badge.img+20
  • Influencer
  • July 23, 2024

Thank you for your response. I have already tried setting the user parameter for the Attribute to expose. During execution, I set $(OUTFIELDS) to "OBJECTID MILLESIME_DATA MILLESIME_DATA2", and I get all three fields in my output. However, when I change the value of $(OUTFIELDS) to "OBJECTID MILLESIME_DATA", I still see all three fields instead of just the two specified. Therefore, I'm looking for an alternative solution, if possible.

Interesting, I have never seen this issue. It seems like the fields to be exposed in the PythonCaller are saved in memory or something. 
I always feed the field names into the User Parameter through a WorkspaceRunner. If the workspace is opened again (by rerunning the WorkspaceRunner), I guess the saved field names are reset.


hnahoulder
Contributor
Forum|alt.badge.img+2
  • Author
  • Contributor
  • July 23, 2024

@nielsgerrits Thank you for your example. I’ll try it and keep you informed.

@joepk It's very strange because when I reopen the application, it recognizes the new value of the user parameter. I tried publishing my workspace to FME Flow, but I still have the same issue.