Skip to main content

Hi all,

 

 

I have a scenario where i have many different types of SMS and Email notifications occurring and i want to create a centralized location on the server for these templates to be edited/adjusted as needed without having to dive into the workbenches every time. Is there a way of doing this? i tried reading the message layout from a text file but it does not resolve the '@attributevalue' sections that i want it to.

FME tries its hardest to be intelligent about resolving @Value() function calls in attributes, but sometimes it doesn't work, e.g. when reading from a text file.

You probably need to break out Python for this, here's a sample workspace with a PythonCaller that will replace all references to @Value(...) with the corresponding attribute value. It assumes that the template to analyze is in the attribute "template" and the result will be output to "template_resolved":

import fmeobjects
import re

def expand_fme_macros(feature):
    input = feature.getAttribute('template')
    matches = re.findall("@"+"Value\((\w+)\)", input)
    for group in matches:
        input = input.replace("@"+"Value(%s)" % group, 
                              str(feature.getAttribute(group) or ''))
    feature.setAttribute('template_resolved', input)

(Notice how I have to split up "@" and "Value" into two separate strings in the Python code to avoid FME trying to interpret it literally, that's how hard FME tries to be intelligent about it...)

Test workspace: template_resolver.fmwt


Reply