Email the results of a database query

Can’t do it with bootstrap though … hmmm. Because the css would have to be have to be in the actual file not as an include. SO you may have to generate a regular table without the generator.

@brad, nope that did not seem to work either, it just left out all the dynamic data, then i tried adding the data back in through the Send Mail component and that also just gave a blank email, well not blank, it had all the static content but none of the dynamic stuff.

I think i am going to have to do a video to show this better.

If I could have exactly what export to csv does but in the body of an email i would be half way there.

May have to go back to your back up plan of a ‘View Order’ link in the email.

1 Like

Is not really clear to me what you are trying to do…

Do you want a mass mailer - mail customers returned by a query?

Or do you want a single mail with list of records inside from a query?

Thats exactly what i would like to do

well as Teodor said that you can’t have repeats in mail body, it is simple to solve with a “variable” or by just joining all the query field records with a formatter

Variable - do a manual append

  • define a variable before the query with Set Variable step and give it empty value
  • do the query
  • repeat througth the query and as sub steps:
  • just mutate the variable with Set Variable but just append new values

Use a join formatter

  • this one is very simple, right after the query do Set Variable and give it as value formatter join string with the record fields

As last step to both solutions - just use the variable in your mail body

Hope it is a bit clear :slight_smile:

2 Likes

Okay going to give it a try quickly, thanks so much, will let everyone know if that works as expected, sounds simple enough :slight_smile:

2 Likes

Just to confirm, because i am getting an empty result.

21

My query is a very simple one that i tested and it returns results
The set variable Value looks like this {{query_for_pre_invoice.join(",", “pr_code”).join(",", “pr_description”)}}
The Send Mail body looks like the second screen shot

I decided to try your second solution as it seemed easier for me to understand

Hi Paul,
I don’t think this code will work, as you cannot join two properties like that. Please use one property only:

{{query_for_pre_invoice.join(",", “pr_description”)}}

Ok, I am hard core enough that i have probably tried this for some 15 hours now in total, lol, i got close enough to know that it really is not going to do what I want it to. I am rather going to just give a link yo the user in an email with a URL parameter to view their invoice if they want.
If any other Bruce Willis fans out there ever manage to get this right please let me know.

Hey there can you post a link to your site so I can look into purchasing something?

I have done this many before by creating a dynamic page ( e.g… “ordersuccess.asp”) with a recordset populated by a querystring value that brings back the required data and formats it complete with a normal repeat regions. Then in the mail I use CreateMHTMLBody (CDOSYS)

with code such as:

objMessage.CreateMHTMLBody “http://yoursite.co.uk/custorder/ordersuccess.asp?OrderID=” & your <%=OrderIDValue %>

That’s asp but could easily be adapted and you get to style the included body exactly as you wish it to appear in the email body.

Hope this is a pointer!

How can I join two or more properties ?
{{query1.join(",", “invoice_number”)}}

I need to send query results via an email …

invoice number | grand total
12345 | 983.00
23720 | 232.00
23299 | 232.00

can you explain me please ?

Any news on this? I am trying to make it work but seems impossible. Will keep on trying, just in any case someone managed to send a query result (order made in my case) through an email please let me know.

Thank you!!

1 Like

Hi Niko,
Can you explain what exactly you need to send by email? Is it one property from the query? What should the mail body include?

Hi Teo,
is the summary of an order made. for example a user buys
1.Prodcut x
2.Product x2
3.Product x3

I would like to send this summary through email. Other data (like total cost etc) is not a problem to send since they are just a value. But for the products I need to query the order and run a repeat so it gets all prodcuts for his order.

Thank you!
PS Although I found a way (outside dmx) to do it, it would be much better if there was a way to do this using ServerConnect & AppConnect. Saying this just to let you know that if it is not possible that’s ok.

If you want to have a repeat region in mail body, which displays a list of records (just as you normally do on page) that is not really possible in the current version.

Check George’s answer above - it explains how to include dynamic data from your query using a join filter. They could be listed as:

You ordered: item1, item2, item3, item99
Total price is: $99

Well actually client wants a better formatted email with product images etc so the join solution won’t do :frowning:
Thank you!

1 Like

I certainly agree that the mail extension is lacking some essential functionality. However by creating an extra column in the product table, I think you should be able to create the email content as you want.

You would have to do this by creating a new column including whatever you need from the other columns, plus any required HTML. You would also need to create a repeat in server connect to populate a variable to include in the email. The extra column could be a calculated/generated column (which as far as I know needn’t take any extra space). For a long calculation, I found it was necessary to use a trigger instead (there seems to be a character limit for computed columns).

(I realise this may already be your solution, outside Wappler, but it’s a sort of solution within Wappler too.)

1 Like

The mailer indeed is missing a repeater that should be handy in this case. I haven’t tested but perhaps you could try the following:

Create a repeater before the mailer, in the repeater you generate the html needed for each item and put it in a variable.

In you email you use the repeater output to join the html you generated there.

2 Likes