10-09-2023 11:44 AM - edited 10-09-2023 11:55 AM
Hi, In my recipe, I am selecting 2 columns from a SQL table, and want to put the results in the body of an email. I get results, but they look like this:
{"rows"=>[{"datetimeoftxn_b5896cc8"=>"2023-10-09 13:59:23.797000000", "listoutput_0ec6e5e5"=>"Test_Last_Name1, Test_First_Name1, Test_Door_Name1 "},
{"datetimeoftxn_b5896cc8"=>"2023-10-09 13:59:23.797000000", "listoutput_0ec6e5e5"=>"Test_Last_Name2, Test_First_Name2, Test_Door_Name2 "}]}
I just want the data in my email like this:
2023-10-09 13:59 Test_Last_Name1, Test_First_Name1, Test_Door_Name1
2023-10-09 13:59 Test_Last_Name2, Test_First_Name2, Test_Door_Name2
The 2 SQL Columns are datetime and nchar. What's the best way to get just the data in my email ?
Solved! Go to Solution.
10-09-2023 12:15 PM
I'd recommend using a message template to format the data into a nicely formatted HTML table, and then insert the table into the email body. You'll need to brush on HTML for the formatting and mustache for the parsing in the message template, but it's definitely worth the effort -- especially if you may need to create more emails in the future.
10-10-2023 02:07 PM - edited 10-10-2023 02:08 PM
For step 8, replace "Step 5 Output" with Step 5 Message. IMO it's very rare that you will use the "Step # Output" directly. You generally want to use the data pills within the step's output.
Anyway, switching gears: let's try something different.
First, make a variable list:
By doing this, you now have the ability to parse and transform (clean up) the values as they go into the list:
Using to_time makes the date string a date object and then using strftime converts it back to a string using the specified formatting. Using strip on the output removes leading/trailing whitespace characters.
Now that it's cleaned up, you can pluck/to_csv and it'll be a lot closer to what you want in your email, but I still recommend using a message template! It's only a few extra steps from here.
10-09-2023 12:15 PM
I'd recommend using a message template to format the data into a nicely formatted HTML table, and then insert the table into the email body. You'll need to brush on HTML for the formatting and mustache for the parsing in the message template, but it's definitely worth the effort -- especially if you may need to create more emails in the future.
10-09-2023 12:22 PM - edited 10-09-2023 12:27 PM
Thanks. I have about 1 hour total experience in Workato and HTML, so not familiar with message templates. I will take a look. I hoped I could do something in the Outlook email step to specify just the data.
10-09-2023 12:52 PM - edited 10-09-2023 12:56 PM
Got it. Learning how to use it will have long term benefits, but here's a quick fix for now.
Make a logger with this formula:
[array_output].pluck('datetimeoftxn_b5896cc8','listoutput_0ec6e5e5').to_csv
to_csv isn't the ideal method to use, but it's the simplest way to get close to what you want:
2023-10-09 13:59:23.797000000,Test_Last_Name1,Test_First_Name1,Test_Door_Name1
If this is close enough, then you're done. If you want to break it up a bit, you can add this to the formula:
.gsub(',','\t')
This will substitute the commas with tabs to give the text a little more breathing room.
You can insert this logger (or the formula) directly into the body of the email.
If you want to get rid of the timestamp in the date, I would suggest reformatting it on the SQL output.
Otherwise, there are longer ways to do this by creating a list variable and reformatting the SQL data as you add it to the list. Then you can convert the list into readable text for your email body.
10-10-2023 05:36 AM
is .gsub(',','\t') adding a TAB ? Is there a way to add a line break to force each record to a new line ?