title: Dataweave script works for preview, fails in actual use
body: <p>Using Studio 6.1.0</p>
  
  <p>Runtime 3.8.2ee</p>
  
  <p>I've written a dataweave script that works fine when I preview the results in the Transform Message window, but when I actually run my application I get an error which suggests a problem with the dataweave script.  </p>
  
  <p>This is the error: </p>
  
  <pre><code>Invalid input "[\n  \t\t({\n  \t\t\teffectiveTerm:
  template.effectiveTerms.effectiveFromTerm,\n  \t\t\tattributeCode: "VARU"\n  \t\t} as :object
  { class: "edu.mit.courseleaf.domain.backfill.OldAttribute" })\n  \t\twhen
  template.units.variableUnits == "Y",", expected flatten, typeOf, using, unzip, capitalize,
  avg, min, lower, upper, max, singularize, not, dasherize, ordinalize, camelize, trim, sizeOf,
  value, pluralize, sum or underscore (line 16, column 24)
  (java.util.concurrent.ExecutionException). Message payload is of type: HashMap
  </code></pre>
  
  <p>Flow with dataweave script, input for preview, json for actual execution are included below.  A couple of comments:</p>
  
  <ol>
  <li>The part of the dataweave script referenced in the error is for the attributes property.  The goal here is to set the property to a list of OldAttribute objects.  The contents of the list depend on two separate element in the source data: the presence of a subjectTemplate.Units.variableUnits == "Y" and a subset of values in the attributes element.</li>
  <li>I know we could go directly from JSON to POJO.  In the full application, we're doing additional processing on the intermediary HashMap so we want to retain the two step conversion.</li>
  <li>edu.mit.courseleaf.domain.backfill.OldAttribute and edu.mit.courseleaf.domain.backfill.SourceSubject are POJOs with default constructors and the proper getters and setters for the properties we're using.</li>
  </ol>
  
  <p>Flow with dataweave script:</p>
  
  <pre><code>&lt;flow name="temp-json-to-map-to-pojo-example-for-so"&gt;
      &lt;json:json-to-object-transformer returnClass="java.util.HashMap" doc:name="JSON to Object"/&gt;
      &lt;set-payload value="#[payload]" mimeType="*/*" doc:name="Set Payload"/&gt;
      &lt;dw:transform-message doc:name="Transform Message"&gt;
          &lt;dw:input-payload doc:sample="sample_data/map.dwl"/&gt;
          &lt;dw:set-payload&gt;&lt;![CDATA[%dw 1.0
              %input payload application/java
              %output application/java
              %function passThroughAttributes(attributeList)  attributeList - "RPT" - "SWE" - "FSEM"
              ---
              using (template = payload.subjectTemplate
                      , attributes = payload.subjectTemplate.attributes
              )
              {
                  subjectCode:template.mainSubjectCode,
                  subjectNumber:template.mainSubjectNumber,
                  attributes: flatten [
                      ({
                          effectiveTerm: template.effectiveTerms.effectiveFromTerm,
                          attributeCode: "VARU"
                      } as :object { class: "edu.mit.courseleaf.domain.backfill.OldAttribute" })
                      when template.units.variableUnits == "Y",
                      passThroughAttributes(attributes)   map (
                      {
                          attributeCode: $,
                          effectiveTerm: template.effectiveTerms.effectiveFromTerm
                      }
                          )  as :object { class: "edu.mit.courseleaf.domain.backfill.OldAttribute" }
                  ]
              }as :object{class : "edu.mit.courseleaf.domain.backfill.SourceSubject"
  
          ]]&gt;&lt;/dw:set-payload&gt;
      &lt;/dw:transform-message&gt;
  &lt;/flow&gt;
  </code></pre>
  
  <p>Sample input for preview:</p>
  
  <pre><code>{
      subjectTemplate: {
          subjectTemplateId: "43C9C99A88B76AFBE053282701126517",
          mainSubjectCode: "HAA",
          mainSubjectNumber: "T101",
          subjectLevel: "U",
          effectiveTerms: {
              effectiveFromTerm:"2017SP",
              effectiveThruTerm: "999999"
          },
          units: {
              variableUnits: "Y",
              lectureUnits: 9,
              labUnits: 3,
              prepUnits: 0,
              totalCreditLimitUnits: 0
          },
          attributes: ["RPT", "XLIS"]
      }
  
  }
  </code></pre>
  
  <p>Screenshot of preview showing attributes property correctly populated
  Actual JSON input for flow</p>
  
  <pre><code>{
      "subjectTemplate": {
          "subjectTemplateId": "43C9C99A88B76AFBE053282701126517",
          "mainSubjectCode": "HAA",
          "mainSubjectNumber": "T101",
          "subjectLevel": "U",
          "effectiveTerms": {
              "effectiveFromTerm": "2017SP",
              "effectiveThruTerm": "999999"
          },
          "units": {
              "variableUnits": "Y",
              "lectureUnits": 9,
              "labUnits": 3,
              "prepUnits": 0,
              "totalCreditLimitUnits": 0
          },
          "attributes": ["RPT", "XLIS"]
      }
  }
  </code></pre>