htmltalend

how to create a HTML-Table in Email with input of Database query


i have a query on a Database which give me Infomation like this: enter image description here

i want to create a HTML Table with Information of the query above and send it to Email of Developer as Error Notification. Can you help me with the HTML code?. Thankyou alot!


Solution

  • This would be one way to achieve what you have been trying for -

    Job Layout -

    enter image description here

    Now, for your use case you would get the data from database - I had manipulated the data to be retrieved from tFixedFlowInput. Once you have the data retrieved you would need to perform few html formatting through tJavaFlex like below -

    enter image description here

    Once done, stored the entire content in a context variable and refer the same in your tSendMail - > "Message".

    Also, make the following change to your tSendMail component to use the HTML formats - enter image description here

    Output -

    enter image description here

    Note: there are many formatting features which could be used through HTML tags, please use them as needed as per your use case - scenario.

    Edit: Yes you would be able to check if there are any rows returned from your Db-Input. Ex: global variable ((Integer)globalMap.get("tMSSqlInput_2_NB_LINE")) would let us know how many lines are returned by the query. Based on this result use RunIf trigger ((Integer)globalMap.get("tMSSqlInput_2_NB_LINE")) > 0 and connect to your job flow so that mail would be send when there are records retrieved from database.