0

I am setting a var like follow:

<set-variable value='#[[]]' doc:name="Set Doc Array" doc:id="bfb46451-ac45-4d73-8189-5b73cdc300b3" variableName="docHashMap"/>

Then I am trying to add elements to that list inside a foreach loop as follow:

<ee:transform doc:name="Transform Message" doc:id="ad2a1dd7-0973-4854-b44c-bdfe8eb54778">
    <ee:message>
        <ee:set-payload><![CDATA[%dw 2.0
import * from dw::core::Binaries
output application/java
---

vars.docHashMap.add({
  "Attachment_Document_Type": vars.factIntakeDocPayload.documentId,
  "Attachement_Content_Type": vars.documentMetadata.contentType,
  "Attachment_Content": toBase64(payload)
})]]></ee:set-payload>
    </ee:message>
</ee:transform>

After the loop I have added a Logger component and I am logging the docHashMap variable as follow:

<logger level="WARN" doc:name="Logger" doc:id="482034d9-00c2-4ae1-8fd3-e999f8ece196" message="#[vars.docHashMap]"/>

But it is empty meaning what I got on the console is just [], why? What I am missing here? I am new to Mule4 by the way.

ReynierPM
  • 17,594
  • 53
  • 193
  • 363

1 Answers1

2

Basically what you need to do is to set again the variable with the new name. Use the set-variable

<ee:transform doc:name="Transform Message" doc:id="ad2a1dd7-0973-4854-b44c-bdfe8eb54778">

            <ee:set-variable variableName="docHashMap"><![CDATA[%dw 2.0
    import * from dw::core::Binaries
    output application/java
    ---

    vars.docHashMap + ({
      "Attachment_Document_Type": vars.factIntakeDocPayload.documentId,
      "Attachement_Content_Type": vars.documentMetadata.contentType,
      "Attachment_Content": toBase64(payload)
    })]]></ee:set-variable>

    </ee:transform>
machaval
  • 4,969
  • 14
  • 20
  • The `set-variable` is not allowed inside a `transform` element and therefore is generating errors while compiling – ReynierPM May 29 '19 at 18:11
  • Sorry forgot to remove the message tag – machaval May 30 '19 at 02:24
  • Yes transform does support set-variable, set-attributes and set-payload. The problem was that it was wrapped by the message tag when in the case of the set-variable it goes directly under transform. Hope it works – machaval May 31 '19 at 13:12
  • You were right, I did it from the UI but in the XML I am able to see exactly the same definition. Bottom line it was going to the payload and I wanted to be on the variable `docHashMap`. Thanks – ReynierPM May 31 '19 at 14:53