Skip to main content
Question

Loop through multiple choice user parameter and copy features from one source to 1-* destinations


I haven't seen a solution to this problem anywhere despite the fact that the question has been told several times.

Scenario: 1 reader and 1 writer. In published parameters you can choose one or many destinations (used by the writer). If one destination is chosen it's pretty straight forward but how do we do when several destinations is choosen? I want to copy all features from the reader to every destination that is selected in the published parameter. I.e. I want to loop the FME-script as many times as there are destinations selected.

It sounds simple but not for me, please help me out on this one.

6 replies

gio
Contributor
Forum|alt.badge.img+15
  • Contributor
  • May 18, 2017

@anderskmark

with destination you refer to featuretypes and or datasets?

You can use a counter to count the chosen destination feature_types, clone the features by the count (using cloner) merge the destination feature_types on the cloned features using copy_number = count (the count attribute form counting the chosen featuretypes) and set a fan-out by destination feature_type on the writer.

This way you won't need to loop.


ebygomm
Influencer
Forum|alt.badge.img+39
  • Influencer
  • May 18, 2017

Instead of looping, I'd do something similar to this. Use the selected parameters to build a list against each feature, then explode it and use a test filter to send each feature copy to the write end location


gio wrote:

@anderskmark

with destination you refer to featuretypes and or datasets?

You can use a counter to count the chosen destination feature_types, clone the features by the count (using cloner) merge the destination feature_types on the cloned features using copy_number = count (the count attribute form counting the chosen featuretypes) and set a fan-out by destination feature_type on the writer.

This way you won't need to loop.

 

I guess I mean datasets. The source is a table in one database and the destination is a table in another database. I have only one source but I want the user the decide to use one or many destination databases with the same table structure of course.

 

 

The choice to select the destinations is made at runtime. That means I cant define, let's say, 3 writers in advance because the user might run the script and only choose 1 dest. Another time the user will select 5 destinations.

ebygomm wrote:

Instead of looping, I'd do something similar to this. Use the selected parameters to build a list against each feature, then explode it and use a test filter to send each feature copy to the write end location

Thanks. But in this case you know in advance that you're targeting 3 destinations. What if the user has selected 4 destinations at runtime? (Or 5...)

 

 


itay
Supporter
Forum|alt.badge.img+17
  • Supporter
  • May 19, 2017

Have a look at the generic writer and the example of the easy translator:

https://knowledge.safe.com/articles/1115/easy-translator-using-fme-server.html


ebygomm
Influencer
Forum|alt.badge.img+39
  • Influencer
  • May 19, 2017
anderskmark wrote:
Thanks. But in this case you know in advance that you're targeting 3 destinations. What if the user has selected 4 destinations at runtime? (Or 5...)

 

 

There are 3 destinations because there are 3 options in the user parameters. You always know how many options are available in the parameters so these are the maximum number of destinations. If you look at the flow, the user has selected 2 options only so data is only written into those two locations, if the user had selected all 3 you would see 9 features after the list exploder instead of six, if they had only selected one you would only see 3 features

 

 


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings