Simple template behaves weirdly in AssignMessage/AssignVariable/Template policy

I'm trying a very simple policy, simplified even more here for convenience.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage name="AssignMyVar">
    <DisplayName>Assign My Var</DisplayName>
    <AssignVariable>
        <Name>replacement1</Name>
        <Value>foobar</Value>
    </AssignVariable>
    <AssignVariable>
        <Name>myvar</Name>
        <Template>{replaceFirst(replacement1, replacement1, "replaced")}</Template>
    </AssignVariable>
</AssignMessage>

I expect myvar to be literally the word replaced, but that doesn't happen, instead myvar is foobar

Something even weirder happens when I inline the original text.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage name="AssignMyVar">
    <DisplayName>Assign My Var</DisplayName>
    <AssignVariable>
        <Name>myvar</Name>
        <Template>{replaceFirst("foobar", "whatever", "replaced")}</Template>
    </AssignVariable>
</AssignMessage>

In this case myvar now contains "foobar" (yeah double quotes included)

This is confusing and even potentially broken. Is it really something wrong or just a very big oversight on my part?

PS. I'm relatively new to Apigee. I normally don't like to ask for help like this and instead just read the docs and figure things out by myself, but this behavior is confusing and surprising.

I've searched the forums and read the docs so many times that I lost count.

Somebody asked something similar before:

https://community.apigee.com/comments/60397/view.html (open comments)

0 2 117
2 REPLIES 2

Pinging somebody with lots of reputation, Ping @Kristopher Kleva 🙂 sorry

Collapse spaces. And use single quotes.

<Template>{replaceFirst(var1,var2,'replaced')}</Template>