Skip to main content

#Flowvars0 人正在讨论

Input json:

 

[{ email: "abcb@hcl.com", status : "NO Id Avalible" }, { email: "kharathi@hcl.com", status : "ID Avalible" }]

 

I need to generate html table response like below in dataweave 1. Can anyone help on this.

 

Expected Response:

<html><body><table border=1 cellpadding=1 cellspacing=1 style=width:500px> <tbody> <tr> <td style=text-align: center;>&nbsp;Email Id</td> <td style=text-align: center;>&nbsp;Update Status</td> </tr> <tr> <td>EMAIL</td> <td>STATUS</td> </tr></body></html> 

5 个回答
  1. 2020年1月17日 04:39

    Thanks @Rohit Reddy for your response.​ .

     

    But i am facing issue while implementing solution this into Dataweave.

     

    Message        : Exception while executing: 

              td @(style:"text-align: center;"): $.status,

                                ^

    Type mismatch for 'Value Selector' operator

       found :string, :name

     required :datetime, :name or

     required :localdatetime, :name or

     required :object, :name or

     required :time, :name or

     required :array, :name or

     required :date, :name or

     required :localtime, :name or

     required :period, :name.

    Payload        : { "email": "abcb@hcl.com", "status" : "NO Id Avalible" }

    Payload Type     : java.lang.String

     

    Flow XML is: [Attached XML file]

     

    <flow name="testerappFlow">

        <poll doc:name="Poll">

          <fixed-frequency-scheduler frequency="1" timeUnit="MINUTES"/>

          <set-payload value="{ "email": "abcb@hcl.com", "status" : "NO Id Avalible" }" doc:name="Set Payload"/>

        </poll>

        <set-variable variableName="payloadVar" value="#[]" doc:name="Variable"/>

        <expression-component doc:name="Expression"><![CDATA[flowVars.payloadVar.add(payload);]]></expression-component>

        <logger message="#flowVars ---- payload: #payload" level="INFO" doc:name="Logger"/>

        <dw:transform-message doc:name="Transform Message" metadata:id="8aad28c5-b6fd-456f-b409-870e8f92b1e5">

          <dw:input-variable doc:sample="sample_data\string_1.dwl" variableName="payloadVar"/>

          <dw:set-payload><![CDATA[%dw 1.0

    %output application/xml

    ---

    html :

      body :

        table @(border:1,cellpadding:1,

        cellspacing:1,style:"width:500px"):

          tbody : 

            tr : {

              td @(style:"text-align: center;"): "Email Id",

              td @(style:"text-align: center;"): "Update Status"

            } ++

            {(flowVars.payloadVar map {

            

              td @(style:"text-align: center;"): $.status,

              td @(style:"text-align: center;"): $.email

        

         }

            )}

            ]]></dw:set-payload>

        </dw:transform-message>

        <logger message="payload at End: #payload" level="INFO" doc:name="Logger"/>

      </flow>

0/9000

im trying the following:

<set-variable variableName="tempPayload" value="#payload" encoding="UTF-8" mimeType="application/json" doc:name="Store Payload temporarily"/>

<json:json-to-object-transformer returnClass="java.lang.Object" doc:name="JSON to Object"/>

<set-payload value="#flowVars.tempPayload" encoding="UTF-8" mimeType="application/json" doc:name="Set Payload back"/>

 

but it corrupts the payload somehow which causes following transform to break in the flow.

6 个回答
  1. 2019年9月10日 19:18

    In Mule 3 use the enricher. Here is an example that wraps the json to object in an enricher and extracts a value into a variable and leaves the payload intact:

     

    <flow name="test">

    <poll frequency="10000" doc:name="Poll">

    <logger level="ERROR" message="started" doc:name="Logger" />

    </poll>

     

    <set-payload doc:name="Set Payload"

    value="{&quot;myField&quot;:&quot;myValue&quot;}" />

    <enricher target="#[flowVars.myFieldVar]">

    <processor-chain>

    <json:json-to-object-transformer

    returnClass="java.util.HashMap" />

    <set-payload value="#[payload.myField]" />

    </processor-chain>

    </enricher>

     

    <choice>

    <when expression="#[flowVars.myFieldVar =='myValue']">

    <logger level="INFO" message="myField is equal to myValue" />

    </when>

    <otherwise>

    <logger level="INFO" message="meh" />

    </otherwise>

    </choice>

     

    <logger level="INFO" message="Payload is still original payload #payload" />

     

     

    </flow>

    LoggerMessageProcessor: myField is equal to myValue

    LoggerMessageProcessor: Payload is still original payload {"myField":"myValue"}

     Note you can also save multiple targets at once for setting multiple variables in one enricher. But the syntax is slightly different. Google the docs to find that syntax.

     

    Also note if you have multiple processors in your enricher they need to be wrapped in a processor-chain, like in the example.

0/9000

I have the following query in Mule 3 and I want to re-write the same in Mule 4. But I am unable to pass the dynamic value properly. I have referred to various online materials and videos on following the syntax but none couldn't help.

Attached below are the queries which I am using in Mule 3 vs Mule 4.

Please let me know if anyone has seen a similar case

 

Mule 3 Query:

SELECT 

DISTINCT CONCAT('${db.host}', '>' ,N.TABLE_CATALOG, '>' ,N.TABLE_SCHEMA, '>' ,N.TABLE_NAME) as FULL_TABLE_NAME,

N.TABLE_CATALOG AS DATABASE_NAME,

N.TABLE_SCHEMA AS SCHEMA_NAME,

N.TABLE_NAME AS TABLE_NAME,

'' AS OBJ_DESCRIPTION,

N.CREATE_DATE AS CREATION_DTTM,

N.MODIFY_DATE AS UPDATE_DTTM

FROM 

(SELECT B.TABLE_CATALOG,B.TABLE_SCHEMA,

B.TABLE_NAME,

CASE WHEN B.TABLE_TYPE='BASE TABLE' THEN 'T' ELSE 'V' END TABLE_TYPE,

CASE WHEN C.create_date IS NULL THEN D.create_date ELSE C.create_date END CREATE_DATE,

CASE WHEN C.modify_date IS NULL THEN D.modify_date ELSE C.modify_date END MODIFY_DATE

 FROM #flowVars.databaseName.INFORMATION_SCHEMA.TABLES B

LEFT JOIN #flowVars.databaseName.sys.tables C ON C.name=B.TABLE_NAME

LEFT JOIN #flowVars.databaseName.sys.views D ON D.name=B.TABLE_NAME ) N

WHERE N.TABLE_TYPE= 'T' AND N.TABLE_SCHEMA IN (${db.schemas})

 

Mule 4 Query which I tried:

 

SELECT

DISTINCT CONCAT('${secure::db.host}', '>' , N.TABLE_CATALOG, '>' , N.TABLE_SCHEMA, '>' , N.TABLE_NAME) as FULL_VIEW_NAME,

N.TABLE_CATALOG AS DATABASE_NAME,

N.TABLE_SCHEMA AS SCHEMA_NAME,

N.TABLE_NAME AS TABLE_NAME,

'' AS OBJ_DESCRIPTION,

N.CREATE_DATE AS CREATION_DTTM,

N.MODIFY_DATE AS UPDATE_DTTM

FROM

(SELECT

B.TABLE_CATALOG,

B.TABLE_SCHEMA,

B.TABLE_NAME,

CASE WHEN B.TABLE_TYPE = 'BASE TABLE' THEN 'T'

ELSE 'V' END TABLE_TYPE,

CASE WHEN C.create_date IS NULL THEN D.create_date

ELSE C.create_date END CREATE_DATE,

CASE WHEN C.modify_date IS NULL THEN D.modify_date

ELSE C.modify_date END MODIFY_DATE

FROM

#vars.databaseName.INFORMATION_SCHEMA.TABLES B

LEFT JOIN #vars.databaseName.sys.tables C ON

C.name = B.TABLE_NAME

LEFT JOIN #vars.databaseName.sys.views D ON

D.name = B.TABLE_NAME) N

WHERE

N.TABLE_TYPE = 'T'

AND N.TABLE_SCHEMA IN (${secure::db.schemas})

4 个回答
0/9000

My flow as below

 

My flow as below

TransformMessage(dw application/json) ->Attach Excel File(set attachment : name: <>.xlsx. value: #flowvars.excelFileContent, content type - binary/octet-stream) ->

Attache CSV File(set attachment : name: <>.csv. value: #flowvars.fileContent, content type - text/csv)->SMTP

Then json in TransformMessage goes to Mail body. Where excelFileContent - payload is set in the flow variable.

 

Thanks in advance!

 

Hello, Did anyone face this issue in.xlsx file is corrupted after received in mail and try to open.  I wanted to send (.xlsx) and csv, two file to smtp as an attachment.  Able to open csv file only problem in .xlsx(content type: binary/octet-stream)

2 个回答
  1. 2020年8月25日 09:44

    Hi Shekh,

    Thank you for your reply.

    Tried the link above. But no luck. Still getting the same issue for the type .xlsx. Able to receive the attachment with 412 bytes - file size. When I save this in my local (file size is zero) and tried to open, getting the below error message. Anything need to check from smtp side? No clue on what I am missing here.

     

    <set-attachment attachmentName="#flowVars.fileNamePattern.xlsx" value="#payload" contentType="text/html" doc:name="Attach Excel File"/>

    Hi Shekh, Thank you for your reply.Tried the link above. But no luck. Still getting the same issue for the type .xlsx. Able to receive the attachment with 412 bytes - file size.

0/9000

Input json:

 

[{ email: "abcb@hcl.com", status : "NO Id Avalible" }, { email: "kharathi@hcl.com", status : "ID Avalible" }]

 

I need to generate html table response like below in dataweave 1. Can anyone help on this.

 

Expected Response:

<html><body><table border=1 cellpadding=1 cellspacing=1 style=width:500px> <tbody> <tr> <td style=text-align: center;>&nbsp;Email Id</td> <td style=text-align: center;>&nbsp;Update Status</td> </tr> <tr> <td>EMAIL</td> <td>STATUS</td> </tr></body></html> 

2 个回答
  1. 2020年1月17日 04:39

    Thanks @Rohit Reddy for your response.​ .

     

    But i am facing issue while implementing solution this into Dataweave.

     

    Message        : Exception while executing: 

              td @(style:"text-align: center;"): $.status,

                                ^

    Type mismatch for 'Value Selector' operator

       found :string, :name

     required :datetime, :name or

     required :localdatetime, :name or

     required :object, :name or

     required :time, :name or

     required :array, :name or

     required :date, :name or

     required :localtime, :name or

     required :period, :name.

    Payload        : { "email": "abcb@hcl.com", "status" : "NO Id Avalible" }

    Payload Type     : java.lang.String

     

    Flow XML is: [Attached XML file]

     

    <flow name="testerappFlow">

        <poll doc:name="Poll">

          <fixed-frequency-scheduler frequency="1" timeUnit="MINUTES"/>

          <set-payload value="{ "email": "abcb@hcl.com", "status" : "NO Id Avalible" }" doc:name="Set Payload"/>

        </poll>

        <set-variable variableName="payloadVar" value="#[]" doc:name="Variable"/>

        <expression-component doc:name="Expression"><![CDATA[flowVars.payloadVar.add(payload);]]></expression-component>

        <logger message="#flowVars ---- payload: #payload" level="INFO" doc:name="Logger"/>

        <dw:transform-message doc:name="Transform Message" metadata:id="8aad28c5-b6fd-456f-b409-870e8f92b1e5">

          <dw:input-variable doc:sample="sample_data\string_1.dwl" variableName="payloadVar"/>

          <dw:set-payload><![CDATA[%dw 1.0

    %output application/xml

    ---

    html :

      body :

        table @(border:1,cellpadding:1,

        cellspacing:1,style:"width:500px"):

          tbody : 

            tr : {

              td @(style:"text-align: center;"): "Email Id",

              td @(style:"text-align: center;"): "Update Status"

            } ++

            {(flowVars.payloadVar map {

            

              td @(style:"text-align: center;"): $.status,

              td @(style:"text-align: center;"): $.email

        

         }

            )}

            ]]></dw:set-payload>

        </dw:transform-message>

        <logger message="payload at End: #payload" level="INFO" doc:name="Logger"/>

      </flow>

0/9000