"Send Email" Button with custom text and fields

  • 0
  • 3
  • Question
  • Updated 1 year ago
  • Answered
I know that there are lots of posts on email generation; I've read many, many of them and still have not found a clear explanation of a solution for what I'm trying to do (i.e., with specific URL formulas etc.).

I have a project tracking database.  When all of the data for a new project is created, I need a button, call it "Send Project" that generates a custom email to an email address included as a field in the main form. 

The basic email notification triggers do not work. I don't want it to send upon addition/deletion/modification of the record.   I've tried to use a toggle field "ReadyToSend", to trigger the form when checked, but could not get that to work.  That said, I do like the ability of custom notifications to combine custom text and form fields.  

I've tried my hand at URL-Formula button in its simple form, like this:

URLRoot() & "db/" & Dbid() & "?a=dr&rid=" & ToText([Record ID#]) & "&dfid=10"

but that has two problems. It simply invokes the Mail interface, and requires me to address the email (which is limited to registered users; the intended recipient is not a Quickbase user).  Second, it sends the whole record (which logically follows from the foregoing).

The text of the email should be something like

Our Ref. No.: [Our Matter]
[Receipient Name]:
Attached you will find a project for [Client]..
<other text and fields>
Please complete the project by [Due Date]...

So is this done via a Notification? A Form? a Button/URL? A combination of these?  
Can you provide the prototype syntax?

Thanks

Robert
 
Photo of ROBERT SACHS

ROBERT SACHS

  • 390 Points 250 badge 2x thumb
  • Perplexed

Posted 1 year ago

  • 0
  • 3
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 26,352 Points 20k badge 2x thumb
You can use script attached to a button to send an on-demand email with custom toList, subject, message and reference an arbitrary record, and from id.

Here is a screenshot of me manually applying the relevant code from the console:





and here is a screenshot of the received email:





Here is the raw code:


Pastie Database
https://haversineconsulting.quickbase.com/db/bgcwm2m4g?a=dr&rid=440

To the extent you want to insert field values into the toListsubject, or  message you can do this by a variety of means from passing formula variables to the script or performing an AJAX request for the field values. 
(Edited)
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 51,166 Points 50k badge 2x thumb
Robert,

This can easily be done totally natively, but I post a response in the morning.
Photo of ROBERT SACHS

ROBERT SACHS

  • 390 Points 250 badge 2x thumb
Thanks, I look forward to it. I've read your other posts already, including your tutorial on URL formulas, and was hoping you'd answer.
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 51,166 Points 50k badge 2x thumb
OK, so this is easy stuff,

Set up a field to trigger the notification on.  I suggest a field type of date/time.  Call it [Date Notification Sent]

Create and Open Notification.  There are two types of Notifications. 

"Recipient" only will go to users and it respects all permissions.
"Open" goes to any email address(es).

If you do not see the option at the very top of the setup for an open Notification, then you need to contact Quick Base support to have you enabled as they seem to default new accounts to disable that for security reasons.

The Subject and body can have any mixture of words and fields.

If there are multiple email address you need to send to at the same time, you choose "a specific list" as the recipient and then the email address fields can just be listed in the box and carefully hand typed typed like this

[email address 1]
[email address 2]
[email address 3]


OK, so you can test that by manually edit the date time field and it will trigger.

Then to make a button you will need a formula URL field.

The URL part is easy

var text URL = URLRoot () "db/" & dbid() and "?act=API_EditRecord&rid=" & [Record ID#]
& "&_fid_99=" & Totext(Now())
& "&apptoken= xxxxxxxxxxx;

 "javascript:" &
"$.get('" & 
$URL & 
"',function(){" &
"location.reload(true);" &
"});" 
& "void(0);"



so that defines a formula variable called URL.  The URL just says to edit the record and put the current date and time into field ID 99.  You will need to change the 99 to the fid of your date/time field.

The apptoken will be required is your app has the requirement for app tokens enabled.  You may want to turn that requirement off.

That last crazy javascript stuff is always standard (If you name your formula variable URL) and you do not need to understand it.  All it does is to execute the URL and refresh the page.  It does hide any error messages though, so if the button does not work, then comment out that javascript stuff or remove it and just put $URL where it was.  That will run the URL and expose any error messages to you.

Let me know how it goes.




 
Photo of Esther

Esther

  • 702 Points 500 badge 2x thumb
I will try this, thank you
Photo of Andreonna

Andreonna

  • 1,040 Points 1k badge 2x thumb
It's not very often I get to answer questions instead of ask. But I just did something similar to what you are asking this week!

I have a document that I send out as a PDF to multiple customers per day. I use an email template, but it's kind of a pain to get to. So I wanted a button that would essentially create this template for me. So I set up a button that will fill in the Subject and Body of the message. 

To start I was able to use the app already built on the exchange to test. That app is called "Tutorial: One click button for outlook". This is a great example of what I needed, although I needed modifications to meet my needs. I would suggest looking at that app though, it was very helpful. 

Basically, on the page I'm sending the email from I added a couple new fields. Two formula text fields called [Subject] and [Body], and a formula URL called [Send Email] which will end up being the button. 

In the [Subject] field I simply set up the text I wanted to be in the subject. My subject included a value from a field so I used a formula text field for this. If you don't need data from a field in the subject you could just use a regular text field and set the default text.  Here is a screenshot of what it looks like for me. 


In the [Body] field I set it up to be laid out how I want. If you need line breaks you will have to use %0D%0A in the formula to include them. So below is what that formula looks like


Finally, in the [Send Email] field you put in the code needed to put this all together in your email client. You can also add a [To] field to auto fill in the recipients of your email as well. See below what I have in my formula. Be sure to put what you want the button to say in the [Link Text] field, and to check the "Display as button..." checkbox.


Finally, you should be able to add the button to your form and test. Here is a screenshot of what I get when I press the button. My email client auto-populates my signature (I've removed most of it from this image) and I can make any changes necessary before sending. 

Sorry for the long explanation, I wanted to provide as much detail as possible. Hope this helps!
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 51,166 Points 50k badge 2x thumb
So just to explain further, Adreonna's solution will cause say Outlook or gmail to open up (what ever your default mail client is) and prefill the email for you to then manually send.

My posted solution will email from QuickBase.  Note also that you can set the "from" to come from the Last Modified by so the recipient can reply to your email.  To see that option you need to set the notification to trigger on single record changes only. 
Photo of ROBERT SACHS

ROBERT SACHS

  • 390 Points 250 badge 2x thumb
thanks to both of you for alternative examples. I like Aredonna's solution because it essentially mirrors my exact work flow.  I'll give that a shot.   Mark, your solution I can use in other ways for emails that I'll send directly.