Skip to main content
Solved

User Parameters and RegEx

  • November 13, 2017
  • 4 replies
  • 64 views

Forum|alt.badge.img

The attached workspace demonstrates the problems I'm having with @ReplaceRegEx and user parameters.  What I'm trying to do is create an output folder name QC within the folder where the input dataset is located.

I've created a private user parameter named OutputFolder of type Folder (output) and set it's default value to:

@ReplaceRegEx($(SourceDataset_MAPINFO),"^(.+)\\.+$","\1\QC")

The intent of the workspace is to simply read the input dataset, create the output folder QC within input dataset folder, and finally write the input dataset to the output folder.

When I run the workspace I get the following error messages:

Could not create output folder `@ReplaceRegEx(C:\temp\InputGeometries.tab,^(.+)\.+$,\1\QC)' for use by MAPINFO writer

Could not create output folder `@ReplaceRegEx(C:\temp\InputGeometries.tab,^(.+)\.+$,\1\QC)' for use by MAPINFO writer

Destination Feature Type Routing Correlator(RoutingFactory): Could not create output folder `@ReplaceRegEx(C:\temp\InputGeometries.tab,^(.+)\.+$,\1\QC)' for use by MAPINFO writer

It's as though FME is literally taking the @ReplaceRegEx expression as the output folder name, and not the result from evaluating the regex.

Also, in the error message, notice how the quotation marks around the pattern and replacement string literals are missing?  Not sure what is happening here.

Any help is greatly appreciated.

Thanks,

Brian

Best answer by takashi

Hi @bbasarich, it doesn't seem that FME evaluates string functions such as @ReplaceRegEx when configuring user parameters before starting translation.
If you intend to create a destination folder called "QC" under the source dataset directory, this Python scripted parameter might help you.

import os
dir = os.path.dirname(FME_MacroValues['SourceDataset_MAPINFO'])
return '%s/QC' % dir if dir else './QC'
View original
Did this help you find an answer to your question?

4 replies

richardatsafe
Safer
Forum|alt.badge.img+10

Hi @bbasarich,

Unfortunately, we cant see the workspace so I'm not entirely sure of the workflow. Would you be able to repost the workspace? That being said I would recommend applying the regexExpression within an attributeManager mid flow opposed to in the private parameter. If you want to use an expression or evaluation within the parameter I would suggest using the scripted Parameter type (Python, or tcl) and use one of those methods.


Forum|alt.badge.img
  • Author
  • November 13, 2017

Here it is replaceregex.fmw

Sorry about that. I accidentally uploaded it twice and then tried to delete one of the uploads. Must have deleted the wrong one.


takashi
Contributor
Forum|alt.badge.img+19
  • Contributor
  • Best Answer
  • November 14, 2017

Hi @bbasarich, it doesn't seem that FME evaluates string functions such as @ReplaceRegEx when configuring user parameters before starting translation.
If you intend to create a destination folder called "QC" under the source dataset directory, this Python scripted parameter might help you.

import os
dir = os.path.dirname(FME_MacroValues['SourceDataset_MAPINFO'])
return '%s/QC' % dir if dir else './QC'

Forum|alt.badge.img
  • Author
  • November 14, 2017
takashi wrote:

Hi @bbasarich, it doesn't seem that FME evaluates string functions such as @ReplaceRegEx when configuring user parameters before starting translation.
If you intend to create a destination folder called "QC" under the source dataset directory, this Python scripted parameter might help you.

import os
dir = os.path.dirname(FME_MacroValues['SourceDataset_MAPINFO'])
return '%s/QC' % dir if dir else './QC'
Thanks @takashi, this works perfectly!

 

 

For posterity, @RichardAtSafe pointed out that FME evaluates @ReplaceRegEx expressions at run-time, but writer destinations are established prior to run time.  I hadn't realized that distinction.

 

 

However, Python scripted parameters are evaluated prior to run time, and therefore, can be used to specify the destination for a writer.  Richard, if I've gotten any of this wrong, please correct.

 

 

Thanks again takashi and Richard for the help.

 

 

Brian

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