Skip to main content
Hi,

 

 

 

I have created a workbench which imports a text file, post import I have used a counter to create an attribute which shows the line number for each row of the file. I then isolate a single row which contains a specific text string (this text string will only ever appear once, but may be in a different line position). Now that I have isolated the string, I want to pass the line number for this string into variable or parameter. After this has been pushed to the variable I want to use a tester to test the variable against each line number if it is < less than then the record is separated form the > records.

 

 

 

I have completed a workaround but I feel it is a bit clunky; the workaround mergers the isolated line number back into each row of the remaining records, then a test is performed to split the features up, line_number > isolated_line_number. However, I would like to try and perform the operation using a variable or parameter.

 

 

 

I have tried using variable setter and create user parameter but it does not do what I want (probably user error).

 

 

 

Thanks

 

 

 

Regards,

 

Hi,

 

 

it is important to understand the difference between a user parameter and a variable.

 

 

A user parameter (published or private) can only be set before the workbench starts. Once the workbench runs, these values cannot be modified. They are the input to your process.

 

 

A variable is a temporary setting that only exists during the execution of the workspace.  You use the VariableSetter and VariableRetriever inside the workspace to get and modify the values of the named variables. Variables are particularly useful when looping through features, e.g. so that one feature can access an attribute value of a preceeding feature.

 

 

David
Hi David,

 

 

Thanks for the explanation regarding the difference and uses of variables and parameters, it is a great help.

 

 

Out of interest if I isolate the value and commit the value using VaraibleSetter, then use a tester to separate can use the Variable Fetcher ACTUALLY within the tester transformer?

 

 

i.e. in psuedo BASIC

 

 

Let A=(isolated line_number value)

 

 

then test remaining records

 

 

If line_number > A then send one way, else send another way

 

 

 

Thanks again,

 

Rob

 

 

 


Hi,

 

 

you cannot reference a variable inside the Tester itself. You must first use the VariableRetriever to read the variable into an attribute, which you then use in the Tester.

 

 

See the doc for more info.

 

 

David
Hi David,

 

 

Ok thanks very much, that is a pain.

 

 

Your work around was essentailly what I had originally done but not using a Variable opion. I isolated the value then used feature merger to join the isolated value back to all the remaining records as a new attribute field, and then tested each record to see it the line-number was less than the added attribute. It worked fine but I felt that a clearer method may exist.

 

 

It is a shame that FME does not allow you to treat the variable as a runtime 'parameter' where you can dervive the value during execution and the  allow you to perforrm tests agaianst the value.

 

 

Thanks again for your help and advice.

 

 

Regards,

 

 

Rob

 


Hi Rob,

 

 

If you will assign the line number of the specific feature to a variable via the VariableSetter, be aware the variable value does not exist before arriving of that feature. I think that using of the FeatureHolder before the VairableRetriever is a frequently used way. Since the FeatureHolder will hold all input features until the last one arrives, the variable will be set certainly before the VariableRetriever.

 

But the VairableRetriever seems to fetch an empty string when the specified variable doesn't exist, so maybe you can determine whether a feature came before the specific feature by testing if the fetched value is empty or not.   Another an (interesting) approach.

 

That is, using "Mutliple Feature Attribute Support" and "Conditional Value Mapping" functionalities of the AttributeCreator.

 

These two AttributeCreators create an attribute named _flag; the value of _flag will be 0 if input feature came before the specific feature (i.e. its attribute value = the specific text), otherwise will be 1. Then, the feature flow can be branched into two ways via the Tester. The second AttributeCreater setting is tricky a little.

 

 

 

 

 

For your information.

 

 

Takashi

Reply